0

我的应用程序的每个方向都有非常不同的 UI 结构。

我应该在 iPad 旋转生命周期的哪个阶段移除,然后添加方向的 UI 以确保最平滑的过渡?

4

1 回答 1

6

处理自动旋转时,您需要关注 4 个主要方法:

shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

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

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

didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

现在,我处理旋转的方式是,例如:

  1. 调整所有帧willAnimateRotationToInterfaceOrientation

  2. 添加/删除子视图(如果需要)willRotateToInterfaceOrientation

  3. 恢复子视图(如果需要)didRotateFromInterfaceOrientation

更一般地说,我修改了所有可设置动画的属性willAnimateRotationToInterfaceOrientationwillRotateToInterfaceOrientation而我在/中进行所有不可动画的修改didRotateFromInterfaceOrientation

这是UIViewController 参考willRotate对/所说的didRotate

要在方向更改期间暂时关闭不需要或可能导致问题的功能,您可以覆盖 willRotateToInterfaceOrientation:duration: 方法并在那里执行所需的操作。然后,您可以覆盖 didRotateFromInterfaceOrientation: 方法,并在方向更改完成后使用它重新启用这些功能。

于 2012-02-11T18:28:33.797 回答