objective-c - 从 UISplitViewController 呈现的 modalViewController 出现错误的方向

标签 objective-c ios cocoa-touch uisplitviewcontroller modalviewcontroller

我有一个UISplitViewController,它设置在我的应用程序的rootView 处。当在我的左 View Controller 中调用 viewDidLoad 时,我会进行检查,然后使用以下内容呈现模态视图 Controller :

SiteConfiguration *config = [[SiteConfiguration alloc] initWithStyle:UITableViewStyleGrouped];
config.firstLoad = YES;
UINavigationController *configNav = [[UINavigationController alloc] initWithRootViewController:config];
if ([Utility isIpad]) {
    configNav.modalPresentationStyle = UIModalPresentationFormSheet;
    configNav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [[AppDelegate instance].splitViewController presentModalViewController:configNav animated:YES];
} else {
    [self presentModalViewController:configNav animated:YES];
}

如果在加载应用程序时 iPad 处于横向模式,则 modalView 显示的方向不正确:

enter image description here

我可以旋转 iPad 来解决这个问题,但为什么它加载错误?我的 SiteConfiguration viewController 中的 shouldAutorotateToInterfaceOrientation: 返回 YES。可能是什么原因造成的?

最佳答案

请注意您选择在何处展示模态 Controller 。 我有一些自定义模态 Controller 的经验,并在

中设置模态 Controller 的方向(及其阴影!)
 - (void)viewDidLoad:(BOOL)animated 

并不总是按预期行事。

将您的代码(presentModalViewController:configNavanimated:YES)放入

 - (void)viewDidAppear:(BOOL)animated 

instead. (Do this as well with any code that sets a subviews frame or does any manipulation of layers, e.g. the shadow layer and shadow properties).

As far as I can tell, the rotation may not be apparent to subviews of the rotated view until after

 - (void)viewDidLoad:(BOOL)animated 
由于线程问题(在主线程将旋转传递到 subview (和模态 Controller )之前,一个线程可能会开始绘制 subview 或模态 Controller 的 View )。比我拥有更多线程经验的人可能能够对此有更多的了解。

关于objective-c - 从 UISplitViewController 呈现的 modalViewController 出现错误的方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11568023/

相关文章:

ios - 绘制自定义 View 不起作用

ios - 如何从 ViewController 转移(推送)到另一个嵌入在 NavigationController 中的 ViewController?

iphone - setDelegate :self, 它是如何工作的?

iphone - 有没有一种方法可以定义某些类可以访问而其他类不能访问的变量?

ios - 日期未显示在 JSQMessagesViewcontroller 聊天页面中

objective-c - 从 textField 获取 int

objective-c - Xcode Objective-c 编译时条件

ios - 自动布局和 UIScrollView

ios - 当用户点击 View 外的任何地方时关闭 View

ios - 用DidBecomeActive通知区分通知中心隐藏和后台返回