【发布时间】:2013-12-05 22:10:57
【问题描述】:
我知道在iOS 6 shouldAutorotate: is NOT being called 之前有人问过这个问题。但我的情况有点不同。
最初,在应用程序启动时,我加载了一个 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
和 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。我做错了什么?请帮帮我。
【问题讨论】:
-
这里有一些(可能)有用的讨论:stackoverflow.com/q/12775265/653513
-
@rokjarc 我在开头提到我已经看到了这个线程,我的问题有点不同。我的窗口的
rootViewController是viewController类,而不是任何UINavigationController或UITabBarController。那里对我没有任何帮助。 -
在 ios7 中的行为是否相同?如果是这样,只需将一个小型 dem 项目放在一个选项卡上,然后将其上传到公共场所。
-
@DavidH 好的。将在一小时内发送给您。
标签: ios iphone ios6 uinavigationcontroller uiinterfaceorientation