まず、カテゴリを作成する必要があります。
UINavigationController+Rotation_IOS6.h
#import <UIKit/UIKit.h>
@interface UINavigationController (Rotation_IOS6)
@end
UINavigationController+Rotation_IOS6.m:
#import "UINavigationController+Rotation_IOS6.h"
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
@end
次に、ランドスケープのみにしたいクラスにこれらのメソッドを実装します。
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
UITabBarController を使用している場合は、UINavigationController を UITabBarController に置き換えてください。このソリューションは、長い検索の後、私にとってはうまくいきました! 私も今のあなたと同じ状況でした!
編集
それで、私はあなたのサンプルを見ました。いくつかの変更を加える必要があります。1 - UINavigationController カテゴリの新しいクラスを作成します。クラスに名前を付けます UINavigationController+Rotation_IOS6 (.h and .m) 2 - メソッドを実装する必要はありませんpreferredInterfaceOrientationForPresentation
。カテゴリは次のようになります。
#import "UINavigationController+Rotation_IOS6.h"
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
@end
3 - ランドスケープでのみ回転させたいクラスで、これを実装に含めます。これはまさに次のようになります。
// Rotation methods for iOS 6
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
4 - iOS 5 の自動回転のメソッドも、ランドスケープで必要なクラス内に含めることをお勧めします。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}