2

我有一个适用于 iOS 8/9 的通用应用程序,其中包含 MainStoryboard_iPhone 和 MainStoryboard_iPad。故事板中的入口点是一个带有标签栏的 RootViewController。RootViewController 控制器非常简单

- (void)viewDidLoad
{
[(VIBAppDelegate *)[[UIApplication sharedApplication] delegate] setRootViewController:self];
self.interfaceOrientationMask = UIInterfaceOrientationMaskAll;
self.preferredOrientation = UIInterfaceOrientationMaskAll;
[super viewDidLoad];}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return self.interfaceOrientationMask;
}

- (BOOL)shouldAutorotate{
return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    UIViewController *currentVC = self.selectedViewController;
    if ([currentVC respondsToSelector:@selector(preferredInterfaceOrientationForPresentation)]) {
        UIInterfaceOrientation orientation = [currentVC preferredInterfaceOrientationForPresentation];
        return orientation;
    }else{
    return self.preferredOrientation;
    }
}

当我在 iPhone 上启动这个应用程序时,supportedInterfaceOrientation 和 shouldAutorotate 方法在应用程序启动期间和设备旋转时被调用。当我在 iPad 上启动应用程序时,它们永远不会被调用。在这两种情况下,viewDidLoad 函数都会按预期调用。

我已经为此困惑了好几个小时。除了布局之外,我认为故事板没有任何差异。两种设备类型都允许 Info.plist 文件中的所有 4 个方向和其他相关键。

<key>UIMainStoryboardFile</key>
<string>MainStoryboard_iPhone</string>
<key>UIMainStoryboardFile~ipad</key>
<string>MainStoryboard_iPad</string>
<key>UIStatusBarHidden</key>
<true/>
<key>UIStatusBarHidden~ipad</key>
<true/>
<key>UIStatusBarStyle</key>
<key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>

在 shouldAutorotate 函数处设置断点表明 UIWindow _shouldAutorotateToInterfaceOrientation:checkForDismissal:is... 正在调用该函数,UIApplicationMain 调用了该函数。这正如预期的那样。

4

1 回答 1

6

在 iOS 9 上,iPad 应用程序默认选择iPad 多任务处理。这意味着它必须始终采用所有方向。由于您没有选择退出iPad 多任务处理,运行时假定您确实始终采用所有方向 - 因此它不需要费心询问您允许哪些方向,因为它已经知道答案(所有这些)。

于 2015-10-04T02:56:03.923 回答