在iOS5中没有调用UIViewController设备旋转委托方法

时间:2011-09-16 13:51:57

标签: uiviewcontroller rotation ios5

我正在开发一个iPhone应用程序。在这个应用程序中,UIViewController(vc1)呈现另一个UIViewController(vc2)。 vc1支持纵向和横向方向; vc2仅支持纵向方向。

  1. 当出现vc2时,它会询问vc1:shouldAutorotateToInterfaceOrientation:并返回YES
  2. 在iOS5(Beta 7)中,willRotateToInterfaceOrientation:,didRotateFromInterfaceOrientation:未被调用此序列。但是,这在iOS4中运行良好。这是iOS5中的错误吗?

2 个答案:

答案 0 :(得分:8)

我向Apple报告了一个错误,我收到了以下回复:

“Engineering已根据以下信息确定此问题的行为符合预期:

演示行为是正确的 - 如果它在以前的版本中表现不同,那就是一个错误。行为中可以想象的意外变化是关于VC1的解散,它不再获得旋转回调,但它将以纵向布局。

当视图控制器自行调出时,还有其他方法可以确定您的方向。由于各种原因,依赖于旋转回调被证明是有问题的。

通常,viewController旋转回调在两种情况下发生:

  1. 窗口层次结构中视图控制器的设备方向更改
  2. 混合界面方向演示。 (底部控制器仅支持纵向,设备处于横向状态,并且呈现支持横向的视图控制器。)然而,这可能是错误的。
  3. 尝试在iOS 5中使用viewWillLayoutSubviews:“

答案 1 :(得分:4)

在iOS5上测试我的应用时遇到了类似的问题。如果在模态视图控制器处于活动状态时方向发生变化,则主视图控制器中的子视图布局会变得混乱。

我所做的是将当前方向标志存储在主控制器中。该标志在主控制器的两个位置更新

  1. willAnimateRotationToInterfaceOrientation:
  2. viewWillLayoutSubviews(仅适用于iOS5)
  3. 我通过比较当前方向和存储值来编写调整子视图的所有逻辑。如果它们不同 - 更新存储的方向,请更新您的子视图。

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {    
        // Any orientation is OK
        return YES;
    }
    
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        portrait = UIInterfaceOrientationIsPortrait(toInterfaceOrientation);
    
        // Code to update subview layout goes here
    }
    
    -(void)viewWillLayoutSubviews
    {
        BOOL isPortraitNow = UIInterfaceOrientationIsPortrait(self.interfaceOrientation);
    
        if(isPortraitNow != portrait)
        {        
            DLog(@"Interfaceorientation mismatch!, correcting");
    
            portrait = isPortraitNow;
    
            // Code to update subview layout goes here
        }
    }