1

我知道这个问题已经在这里问iOS 6 shouldAutorotate: is NOT being called。但是我的情况有点不同。
最初,在应用程序启动予加载的viewController像
self.window.rootViewController = self.viewController;
和当这一观点被我使用,其具有5的UINavigationController为每个标签定制的TabBar图(从UIView的继承)加载。这个的viewController类的代码是:
iOS 6:supportedInterfaceOrientations被调用,但不应该叫Antalotate

\\\ .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 


和M档是

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

CGFloat orginHeight = self.view.frame.size.height- 60; 
_tabbar = [[tabbarView alloc]initWithFrame:CGRectMake(0, orginHeight, 320, 60)]; 
_tabbar.delegate = self; 
[self.view addSubview:_tabbar]; 
_arrayViewcontrollers = [self getViewcontrollers]; 
[self touchBtnAtIndex:0]; 
} 
-(void)touchBtnAtIndex:(NSInteger)index \\This delegate method is called on every custom tabBar button clicked. 
{ 
UIView* currentView = [self.view viewWithTag:SELECTED_VIEW_CONTROLLER_TAG]; 
[currentView removeFromSuperview]; 

UINavigationController *viewController = [_arrayViewcontrollers objectAtIndex:index]; 
viewController.view.tag = SELECTED_VIEW_CONTROLLER_TAG; 
viewController.view.frame = CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height- 50); 

[self.view insertSubview:viewController.view belowSubview:_tabbar]; 
} 
-(NSArray *)getViewcontrollers 
{ 
FirstViewController *firstController = [[FirstViewController alloc]initWithNibName:@"FirstViewController" bundle:nil]; 
SecondViewController *secondController = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil]; 
ThirdViewController *thirdController = [[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil]; 
ForthViewController *forthController = [[ForthViewController alloc]initWithNibName:@"ForthViewController" bundle:nil]; 
FifthViewController *fifthController = [[FifthViewController alloc]initWithNibName:@"FifthViewController" bundle:nil]; 

navigation1 = [[UINavigationController alloc] initWithRootViewController:firstController]; 
navigation2 = [[UINavigationController alloc] initWithRootViewController:secondController]; 
navigation3 = [[UINavigationController alloc] initWithRootViewController:thirdController]; 
navigation4 = [[UINavigationController alloc] initWithRootViewController:forthController]; 
navigation5 = [[UINavigationController alloc] initWithRootViewController:fifthController]; 

NSArray* tabBarItems = [[NSArray alloc] initWithObjects:navigation1,navigation2,navigation3,navigation4,navigation5, nil]; 
return tabBarItems; 
} 

我还实施的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类,而不是任何UINavigationControllerUITabBarController。我做错了什么?请帮帮我。

+0

一些(可能)有用的讨论在这里:http://stackoverflow.com/q/12775265/653513 –

+0

@rokjarc我在开始时提到我已经看到这个线程,我的问题有点不同。我的窗口的'rootViewController'是'viewController'类,而不是'UINavigationController'或'UITabBarController'。那里没有任何帮助。 –

+0

ios7中的行为是否相同?如果是这样的话,只需将一个小型dem项目放在一个标签中,然后将其上传到公共场所即可。 –

回答

3

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

- (BOOL)shouldAutorotate 
{ 
    NSLog(@"ViewController shouldAutorotate super=%d", [super shouldAutorotate]); 
    return YES; 
} 
- (NSUInteger)supportedInterfaceOrientations 
{ 
    NSLog(@"ViewController supportedInterfaceOrientations"); 
    return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
} 

,你会看到系统不断发送这两个消息。您的代码可以查询活动的导航控制器,以查看您希望返回的值。我不喜欢使用一个类别来覆盖UINavigation控制器上的这些类别 - 它的工作原理有些侥幸,并且导入其他一些类似的库可能会在稍后导致意想不到的后果。只需创建一个非常简单的子类,并完成这两者。自iOS4以来,我一直在用UITabBarController和UINavigationController来做这件事,并且从来没有遇到过问题。

+0

它按我的预期工作。你真的是一个生命拯救者(编程) –

相关问题