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?
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, eg:
adjust all the frames in willAnimateRotationToInterfaceOrientation
;
add/remove subviews (if needed) in willRotateToInterfaceOrientation
;
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.