Question

My app has very different UI structures for each orientation.

At what stage in the rotation lifecycle of an iPad should I remove, then add the orientation's UI to ensure the smoothest transition?

Was it helpful?

Solution

When handling autorotation, you have 4 main methods to care about:

shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation                                   duration:(NSTimeInterval)duration

willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                            duration:(NSTimeInterval)duration

didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

Now, the way I handle the rotation is, e.g.:

  1. adjust all the frames in willAnimateRotationToInterfaceOrientation;

  2. add/remove subviews (if needed) in willRotateToInterfaceOrientation;

  3. restore subviews (if needed) in didRotateFromInterfaceOrientation.

More in general, I modify all properties that are animatable in willAnimateRotationToInterfaceOrientation; while I do all modifications that are not animatable in willRotateToInterfaceOrientation/didRotateFromInterfaceOrientation.

This is what the UIViewController reference says about willRotate/didRotate:

To temporarily turn off features that are not needed or might otherwise cause problems during the orientation change, you can override the willRotateToInterfaceOrientation:duration: method and perform the needed actions there. You can then override the didRotateFromInterfaceOrientation: method and use it to reenable those features once the orientation change is complete.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top