[英]iOS: Rotating an iPad, what stage to change view?
My app has very different UI structures for each orientation. 我的应用程序针对每个方向的UI结构都非常不同。
At what stage in the rotation lifecycle of an iPad should I remove, then add the orientation's UI to ensure the smoothest transition? 我应该在iPad的旋转生命周期的哪个阶段删除,然后添加方向的UI以确保最平稳的过渡?
When handling autorotation, you have 4 main methods to care about: 处理自动旋转时,您需要注意以下4种主要方法:
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
; 调整willAnimateRotationToInterfaceOrientation
所有帧;
add/remove subviews (if needed) in willRotateToInterfaceOrientation
; 在willRotateToInterfaceOrientation
添加/删除子视图(如果需要);
restore subviews (if needed) in didRotateFromInterfaceOrientation
. 在didRotateFromInterfaceOrientation
中还didRotateFromInterfaceOrientation
视图(如果需要)。
More in general, I modify all properties that are animatable in willAnimateRotationToInterfaceOrientation
; 一般来说,我将修改willAnimateRotationToInterfaceOrientation
中可设置动画的所有属性; while I do all modifications that are not animatable in willRotateToInterfaceOrientation
/ didRotateFromInterfaceOrientation
. 虽然我会执行willRotateToInterfaceOrientation
/ didRotateFromInterfaceOrientation
所有无法修改的修改。
This is what the UIViewController reference says about willRotate
/ didRotate
: 这就是UIViewController参考关于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. 要临时关闭不需要的功能,否则可能会在方向更改过程中导致其他问题的功能,您可以覆盖willRotateToInterfaceOrientation:duration:方法并在其中执行所需的操作。 You can then override the didRotateFromInterfaceOrientation: method and use it to reenable those features once the orientation change is complete. 然后,您可以覆盖didRotateFromInterfaceOrientation:方法,并在方向更改完成后使用它重新启用这些功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.