iOS 6:已调用supportedInterfaceOrientations,但未调用shouldAutorotate

iOS 6:已调用supportedInterfaceOrientations,但未调用shouldAutorotate,ios,iphone,ios6,uinavigationcontroller,uiinterfaceorientation,Ios,Iphone,Ios6,Uinavigationcontroller,Uiinterfaceorientation,我知道这个问题以前在这里被问过。但我的情况有点不同。 最初,在应用程序启动时,我加载一个viewController,如 self.window.rootViewController=self.viewController 当这个视图被加载时,我使用的是一个自定义的tabBar视图(继承自UIView),每个选项卡有5个UINavigationController。此viewController类的代码为: \\\ .h File @protocol tabbarDelegate <NS

我知道这个问题以前在这里被问过。但我的情况有点不同。
最初,在应用程序启动时,我加载一个viewController,如
self.window.rootViewController=self.viewController
当这个视图被加载时,我使用的是一个自定义的tabBar视图(继承自UIView),每个选项卡有5个UINavigationController。此viewController类的代码为:

\\\ .h File

@protocol tabbarDelegate <NSObject>
-(void)touchBtnAtIndex:(NSInteger)index;
@end
@class tabbarView;
@interface ViewController : UIViewController <tabbarDelegate>
@property(nonatomic,strong) tabbarView *tabbar;
@property(nonatomic,strong) NSArray *arrayViewcontrollers;
@property(nonatomic,strong) UINavigationController * navigation1;
@property(nonatomic,strong) UINavigationController * navigation2;
@property(nonatomic,strong) UINavigationController * navigation3;
@property(nonatomic,strong) UINavigationController * navigation4;
@property(nonatomic,strong) UINavigationController * navigation5;
@end
我还实现了UINavigationController的旋转类别:

@implementation UINavigationController (autoRotation)
-(BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}

-(NSUInteger)supportedInterfaceOrientations {
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}

我的问题是只调用了
supportedInterfaceOrientations
方法,并且从不调用
shouldAutorotate
。主窗口的rootViewController是
ViewController
类,而不是任何
UINavigationController
UITabBarController
。我做错了什么?请帮助我。

如果将这些添加到根视图控制器:

- (BOOL)shouldAutorotate
{
    NSLog(@"ViewController shouldAutorotate super=%d", [super shouldAutorotate]);
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    NSLog(@"ViewController supportedInterfaceOrientations");
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
您将看到系统不断地发送这两条消息。那里的代码可以查询活动导航控制器,以查看如果需要返回哪些值


此外,我不喜欢在UINavigation控制器上使用类别来覆盖这些内容,这有点像是侥幸,导入其他类似的库可能会在以后造成意外的后果。只需创建一个非常简单的子类,并超越这两个。从iOS4开始,我就一直在使用UITabBarController和UINavigationController,从来没有遇到过问题。

这里有一些(可能)有用的讨论:@rokjarc我在开始时提到,我看到了这个线程,我的问题有点不同。我的窗口的
rootViewController
viewController
类,而不是任何
UINavigationController
UITabBarController
。这对我没有任何帮助。在ios7中的行为也一样吗?如果是这样的话,只需将一个小型dem项目放在一个选项卡上,然后将其上载到公共场所。@DavidH OK。我会在一小时内把它寄给你。它像我预期的那样工作。你真的是一个救生员(通过编程)
- (BOOL)shouldAutorotate
{
    NSLog(@"ViewController shouldAutorotate super=%d", [super shouldAutorotate]);
    return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
    NSLog(@"ViewController supportedInterfaceOrientations");
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}