gpt4 book ai didi

objective-c - didRotateFromInterfaceOrientation : is not called for controller which presented modal controller on iOS 5

转载 作者:搜寻专家 更新时间:2023-10-30 19:48:17 25 4
gpt4 key购买 nike

有一个 View Controller (我们将其命名为 parent),它使用 presentModalViewController:animated: 呈现其他 View Controller (我们将其命名为模态),然后旋转设备。两个 Controller 都支持所有方向。这是发生了什么:

  1. 旋转后,模态 Controller 立即收到 didRotateFromInterfaceOrientation:
  2. 就在关闭模态 Controller 之前,父 Controller 也接收到 didRotateFromInterfaceOrientation:。但是,仅当基础 SDK 设置为 4.3(或更低)时才会发生。如果将 base SDK 设置为 5,则父 Controller 不会收到此消息。在 4.3 中,我根据 didRotateFromInterfaceOrientation: 中的新方向更新了父界面,并且在隐藏模态 Controller 后正确显示,但在 iOS 5 中,它没有被调用,并且在隐藏模态之后父界面变得困惑 Controller 。

那么,如果在模态 Controller 可见的情况下旋转设备,我应该怎么做才能将父 Controller 的界面正确更新到新的方向?

最佳答案

我遇到过类似的问题。我的解决方案是将我的方向处理代码移动到一个单独的方法中,并从旋转方法和 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

关于objective-c - didRotateFromInterfaceOrientation : is not called for controller which presented modal controller on iOS 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8861753/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com