すべてのビュー コントローラーの回転を有効または無効にする場合は、サブクラス化する必要はありませんUINavigationController
。代わりに次を使用します。
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
あなたのAppDelegate
。
アプリですべての向きをサポートするが、PARENT ビュー コントローラー (UINavigationController
スタックなど) で異なる向きをサポートする予定がある場合は、使用する必要があります。
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
AppDelegate
PARENT View Controller の次のメソッドと組み合わせて使用します。
- (BOOL)shouldAutorotate
と
- (NSUInteger)supportedInterfaceOrientations
ただし、同じナビゲーション スタック (私のように) 内の異なる CHILDREN ViewController で異なる方向設定を行う予定がある場合は、ナビゲーション スタック内の現在の ViewController を確認する必要があります。
UINavigationController
サブクラスで次のものを作成しました。
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
int interfaceOrientation = 0;
if (self.viewControllers.count > 0)
{
DLog(@"%@", self.viewControllers);
for (id viewController in self.viewControllers)
{
if ([viewController isKindOfClass:([InitialUseViewController class])])
{
interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
else if ([viewController isKindOfClass:([MainViewController class])])
{
interfaceOrientation = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
else
{
interfaceOrientation = UIInterfaceOrientationMaskAllButUpsideDown;
}
}
}
return interfaceOrientation;
}
子ViewControllersから提示されたView Controllerの回転設定を制御することはできなくなるため、現在ナビゲーションスタックにあるView Controllerを何らかの方法でインターセプトする必要があります。それが私がしたことです:)。それが役立つことを願っています!