MainStoryboard_iPhone と MainStoryboard_iPad を含む iOS 8/9 用のユニバーサル アプリがあります。ストーリーボードのエントリ ポイントは、タブ バーを持つ 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 関数にブレークポイントを配置すると、UIApplicationMain によって呼び出される UIWindow _shouldAutorotateToInterfaceOrientation:checkForDismissal:is... によって呼び出されていることがわかります。これは予想通りです。