【问题标题】:iOS: Rotating an iPad, what stage to change view?iOS:旋转 iPad,什么阶段可以改变视图?
【发布时间】:2012-02-11 18:03:12
【问题描述】:

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

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

【问题讨论】:

    标签: ios ipad cocoa-touch screen-rotation


    【解决方案1】:

    在处理自动旋转时,您需要关注 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 中恢复子视图(如果需要)。

    更一般地说,我修改了willAnimateRotationToInterfaceOrientation 中所有可动画的属性;而我在willRotateToInterfaceOrientation/didRotateFromInterfaceOrientation中做了所有不可动画的修改。

    这就是UIViewController reference 所说的willRotate/didRotate

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

    【讨论】:

      猜你喜欢
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-26
      • 2011-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多