我的应用针对每个方向都有非常不同的 UI 结构。
我应该在 iPad 旋转生命周期的哪个阶段删除,然后添加方向的 UI 以确保最平滑的过渡?
最佳答案
处理自转时,主要有4个方法需要关心:
shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
现在,我处理旋转的方式是,例如:
调整
willAnimateRotationToInterfaceOrientation
中的所有帧;在
willRotateToInterfaceOrientation
中添加/删除 subview (如果需要);在
didRotateFromInterfaceOrientation
中恢复 subview (如果需要)。
更一般地说,我修改了 willAnimateRotationToInterfaceOrientation
中所有可设置动画的属性;而我在 willRotateToInterfaceOrientation
/didRotateFromInterfaceOrientation
中进行所有不可设置动画的修改。
这就是UIViewController reference关于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.
关于iOS:旋转 iPad,什么阶段可以改变 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9242616/