shouldAutorotate没有被调用,虽然我有类的uinavigationcontroller转发呼吁

问题描述:

我有点困惑。 我想我的应用程序正好在我的5个View Controller中的一个中旋转。 我创建了一个类别的UINavigationController实现在IOS 6shouldAutorotate没有被调用,虽然我有类的uinavigationcontroller转发呼吁

#import "UINavigationController+IOS6Rotation.h" 


@implementation UINavigationController (IOS6Rotation) 

-(BOOL)shouldAutorotate 
{ 
    return [self.topViewController shouldAutorotate]; 
} 

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    if (INTERFACE_IS_PAD) { 
     return UIInterfaceOrientationLandscapeLeft; 
    } 
    else{ 
     return UIInterfaceOrientationPortrait; 
    }  
} 
@end 

我也有我的所有ViewControllers不应旋转实现了这些方法旋转必要的方法。

- (BOOL)shouldAutorotate { 
    return NO; 
} 

- (BOOL)supportedInterfaceOrientations { 
    if (INTERFACE_IS_PAD) { 
     return UIInterfaceOrientationMaskLandscape; 
    } 
    else{ 
     return UIInterfaceOrientationMaskPortrait; 
    } 
} 

谁应该转动;是在shouldAutorotate

启动时的一个,我使用一个额外的viewController显示一个闪屏。这个SplashScreen像这样显示为RootViewController。

vc_splash = [[SplashScreenViewController alloc] initWithNibName:@"SplashScreenViewController" bundle:[NSBundle mainBundle]]; 
[self.window setRootViewController:vc_splash]; 

DefaultSHKConfigurator *configurator = [[MySHKConfigurator alloc] init]; 
[SHKConfiguration sharedInstanceWithConfigurator:configurator]; 
[self.window makeKeyAndVisible]; 

当我完成加载我的数据库,splashscreen交换为主屏幕。

self.viewController = [[MainViewController alloc] initWithNibName:@"MainViewController_iPhone" bundle:nil]; 
    UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: self.viewController]; 
    [self.window setRootViewController: navControl]; 

现在的问题是,只有我的飞溅屏幕调用shouldAutorotate,但其他屏幕没有。 有人可以告诉我,我是否错过了这里的一些必需品? 我想我已经做了所有必要的东西来获取BL ****Ÿ自转在iOS 6的正常工作......

Thx提前, Maverick1st

**更新* * 如果你希望你的iPad在景观开始​​,一定要在你的shouldAutoRotate返回YES,

+0

你为什么要实施'UINavigatorController'类别,当你实现了所有的方法,在5'ViewController's的4呢?我认为实现该类别的目的是为了避免重复代码。既然你走了这么远,为什么不直接在你想旋转的'ViewController'中直接实现三个旋转方法呢? – Bill

+0

您需要转发类别中的方法调用,因为当viewcontroller包含在tabbarcontroller或navigationcontroller中时,viewcontroller中的方法不会被调用。我已经在选项卡中使用tabbar和navigationcontroller创建了一个应用程序,并且它工作正常。它根本不知道我这次做错了什么,因为它应该在我看来是正确的。 – Maverick1st

,这是为我工作在application添加supportedInterfaceOrientationsForWindow 方法:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController; 
    [navigationController shouldAutorotate]; 
    [navigationController preferredInterfaceOrientationForPresentation]; 
    return UIInterfaceOrientationMaskAll; 
} 

而且在applicationdelegate补充一点:

@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 
+0

从supportedIntefaceOrientationsForWindow显式调用shouldAutorotate会在我的代码中产生一个infinit循环。 我也有一个类别,所以我没有理由在appDelegate中执行第二个操作。或者[self.viewcontrollers lastObject]和self.topViewController之间有区别吗? – Maverick1st

+0

[self.viewcontrollers lastObject]'和'self.topViewController'之间没有区别。从其他视图控制器中删除类别并仅在appDelegate –

+1

中添加,但这并不能解决问题,因为supportedInterfaceOrientationsForWindow一直在调用beeing,所以您的代码会导致无限循环。 – Maverick1st