Irfanlone
Irfanlone

Reputation: 564

Rotation with Autolayout not working

the below method is not called when i rotate my device with Autolayout ON in IB.

willRotateToInterfaceOrientation:duration:

Firstly does the above methods don't wok with autolayout? the method gets called with Autolayout turned off. I am trying to change the background Image of my view on rotation, Not sure how to achieve that with autolayout constaints ON?

I also tried to use procedure by Moin but I have a huge view hierarchy and the methods are called from superview onwards, and and i have lot of other code in other methods like. So it didn't help

didRotateFromInterfaceOrientation  

Upvotes: 2

Views: 884

Answers (2)

Irfanlone
Irfanlone

Reputation: 564

The -willRotateToInterfaceOrientation:duration: gets called on the root viewcontroller and all its child viewcontrollers and works with autolayout. If you want these methods to get called on a particular viewcontroller, It must be child viewcontroller of the root viewcontroller.

It took me a while to figure out that the hierarchy from the root to the last viewcontroller was breaking at some point. I just had to add it back as the child view controller.

Upvotes: 1

SwiftArchitect
SwiftArchitect

Reputation: 48514

The short answer: -willRotateToInterfaceOrientation:duration: works with AutoLayout.

The long answer: Assuming you are using NIB, so many compounding issues can go wrong ; I have compiled this checklist:

  1. Did you set your custom UIViewController in IB as recommended by @JoshJustice at Loaded nib but the view outlet was not set - new to InterfaceBuilder
  2. Are you properly handling auto-rotation as recommended by @nybon at UIViewController does not auto rotate
  3. Did you set a global orientation in the plist as recommended by @NateFlink at Handling autorotation for one view controller in iOS7
  4. Does your custom UIViewController respond to -supportedInterfaceOrientations with incorrect values? See recommended response by @AndrewHershberger at preferredInterfaceOrientationForPresentation must return a supported interface orientation (iOS 6)

Upvotes: 1

Related Questions