didRotateFromInterfaceOrientation:不会为在iOS 5上显示模态控制器的控制器调用

时间:2012-01-14 10:55:27

标签: objective-c cocoa-touch uiviewcontroller ios5 rotation

有一个视图控制器(我们将其命名为parent),它使用presentModalViewController:animated:显示其他视图控制器(让我们将其命名为模态),然后旋转设备。两个控制器都支持所有方向。这里发生了什么:

  1. 旋转后,模态控制器接收didRotateFromInterfaceOrientation:
  2. 在解除模态控制器之前,父控制器也接收didRotateFromInterfaceOrientation:。但是,仅当基本SDK设置为4.3(或更低)时才会发生。如果将基本SDK设置为5,则父控制器不会收到此消息。在4.3中,我根据didRotateFromInterfaceOrientation:中的新方向更新了父接口,并且在隐藏模态控制器后显示正确,但是在iOS 5中,它没有被调用,并且隐藏模态控制器后父接口被搞乱了。
  3. 那么,如果在模态控制器可见的情况下旋转设备,我应该怎么做才能正确地将父控制器的界面更新为新的方向?

2 个答案:

答案 0 :(得分:1)

我遇到过类似的问题。我的解决方案是将我的方向处理代码移动到一个单独的方法中,并调用旋转方法和viewWillAppear:

//.h
@interface SomeViewController

- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)orientation;

@end


//.m
@implementation SomeViewController


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    [self layoutForInterfaceOrientation:currentOrientation];
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toOrientation duration:(NSTimeInterval)duration {

    [self layoutForInterfaceOrientation:toOrientation];
}

- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)orientation {

    // layout views
}

@end

答案 1 :(得分:0)

这可能会解决问题。它对我有用:

modal.modalPresentationStyle = UIModalPresentationCurrentContext;