shouldAutorotate呼吁iPhone,但不是在iPad上

我有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函数按预期调用。

我一直在困惑这个好几个小时。 除布局以外,我发现故事板没有任何区别。 这两种设备types都允许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调用。 这是预期的。

在iOS 9上,默认情况下iPad应用程序会selectiPad多任务处理 。 这意味着它必须始终采取所有的方向。 由于您没有select退出 iPad多任务处理,因此运行时会假定您始终采用所有的方向 – 因此无需再问您什么方向,因为它已经知道答案(所有方向)。