iOS:旋转 iPad,什么阶段可以改变 View ?

标签 ios ipad cocoa-touch screen-rotation

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

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

最佳答案

处理自转时,主要有4个方法需要关心:

shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

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

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

didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

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

  1. 调整willAnimateRotationToInterfaceOrientation中的所有帧;

  2. willRotateToInterfaceOrientation 中添加/删除 subview (如果需要);

  3. 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/

相关文章:

objective-c - "[setToolBarHidden:YES]"不工作

ios - 对 textFieldDidEndEditing 的操作

android - React Native 中 redux over normal state 机制的用例

ios - 在 IOS 应用程序中显示输出

ios - iOS splitViewcontroller 的不同自定义 View Controller

iphone - 是否有可用于 iPhone/iPad 开发的第三方库可以帮助我在屏幕上制作二维矩阵 View ?

ipad - 在选项卡式 UI 弹出窗口中使用 ImagePicker

iphone - 如何只显示有电话号码的联系人?

ios - 用户在 iOS 中进行应用内购买并且没有付款数据时的流程

ios - 将数据从 NSArray 加载到 NSManagedObject