通过拆分视图控制器启动模式视图的问题

时间:2011-01-20 18:09:46

标签: ios-simulator uisplitviewcontroller

我创建了一个以模态视图启动页面开头的拆分视图应用程序。问题是模态视图总是以纵向模式启动,即使ipad处于横向模式。如果我旋转ipad几次,它会适当旋转。我在Info.plist中设置了UIInterfaceOrientation,但它没有任何影响。

didFinishLaunchingWithOptions 中,我使用以下代码

...
[self.window addSubview:splitViewController.view];
SplashViewController *modalView = [[SplashViewController alloc] intiWithNibName:nil bundle:nil];
modalView.modalPresentationStyle = UIModalPresentationFullScreen;
[splitViewController presentModalViewController:modalView animated:YES];
...

关于如何确保模态视图在横向中启动的任何建议?

3 个答案:

答案 0 :(得分:1)

使用Matt Gemmell's MGSplitViewController时遇到了类似的问题。在我的例子中,通过尝试从详细视图控制器(即UISplitViewController标准中的“右侧”窗格)内部以FormSheet模式打开模态视图控制器,我的模态视图强制界面旋转为纵向。 我通过覆盖模态视图控制器找到了解决方案 - > shouldAutorotateToInterfaceOrientation:让他回来NO:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return NO;
}

通过这种方式,当出现模态时,由于某种原因,操作系统会尝试将其强制为肖像。通过回答NO,视图不再旋转,一切正常。

答案 1 :(得分:1)

我认为这是更好的方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
        return YES;
    }
    return NO;
}

答案 2 :(得分:0)

在启动模态视图的文件中,您需要更改/覆盖以下功能。您只需复制并粘贴以下代码,您就可以在 portrait 横向模式中启动模态视图:

- (BOOL)shouldAutoRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}
祝你好运。

编辑:我说的是肖像模式,而不是我的意思:横向模式。

相关问题