私のアプリケーションはナビゲーション ベースで、主に縦向きで実行されますが、1 つのビュー コントローラーは縦向きと横向きの両方をサポートします。問題は、ランドスケープビューコントローラーから新しいビューコントローラーをプッシュすると、ポートレートモードで欲しいのに、新しいビューコントローラーもランドスケープモードでプッシュされることです。
また、ランドスケープコントローラーからビューコントローラーをポップすると、ポップされたビューコントローラーがポートレートモードで表示されます。
私のコードの何が問題なのかわかりません。
これらのオリエンテーション サポートに使用される私のコード スニペットと情報を次に示します。
info.plist ファイルでは、すべての向きをサポートしていましたが、縦向きは逆さまでした。
以下のように、ナビゲーションコントローラーのカテゴリにもカテゴリを追加しました。
@implementation UINavigationController(Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
また、すべてのクラスのスーパークラスとして機能する UIViewController サブクラスも作成しました。スーパー クラスのオリエンテーション メソッドは次のとおりです。
@implementation ParentViewController
- (BOOL)shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
@end
また、ランドスケープをサポートするオリエンテーション メソッド コントローラーは次のとおりです。
@implementation LandscapeController
#pragma mark -
#pragma mark Orientation Methods
- (BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
前もって感謝します。