我知道这个问题已经在这里问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
类,而不是任何UINavigationController
或UITabBarController
。我做错了什么?请帮帮我。
一些(可能)有用的讨论在这里:http://stackoverflow.com/q/12775265/653513 –
@rokjarc我在开始时提到我已经看到这个线程,我的问题有点不同。我的窗口的'rootViewController'是'viewController'类,而不是'UINavigationController'或'UITabBarController'。那里没有任何帮助。 –
ios7中的行为是否相同?如果是这样的话,只需将一个小型dem项目放在一个标签中,然后将其上传到公共场所即可。 –