iOS:旋转iPad,改变观点的阶段?

Ian*_*ink 0 cocoa-touch ipad screen-rotation ios

我的应用程序针对每个方向具有非常不同的UI结构

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

ser*_*gio 6

处理自动旋转时,您有四种主要方法需要关注:

shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

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

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

didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
Run Code Online (Sandbox Code Playgroud)

现在,我处理轮换的方式是,例如:

  1. 调整所有帧willAnimateRotationToInterfaceOrientation;

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

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

更一般地说,我修改了所有可动画的属性willAnimateRotationToInterfaceOrientation; 虽然我做了所有在willRotateToInterfaceOrientation/ 中都没有动画的修改didRotateFromInterfaceOrientation.

这是UIViewController参考文献中关于willRotate/的内容didRotate:

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