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