的UITabBarController presentmodal自动旋转问题
问题描述:
我有UITabBarController
子类处理旋转问题:的UITabBarController presentmodal自动旋转问题
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return [self.selectedViewController supportedInterfaceOrientations];
}
-(BOOL)shouldAutorotate{
return YES;
}
从
tabbatcontroller
的
UIViewController
的一个
,现在我提出一个新的UIViewController
:
MainVC *mainVC = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil];
UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:mainVC];
radioNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainNav animated:YES];
而且在这个新的导航,我想禁用自动旋转,只允许肖像:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate{
return NO;
}
但旋转仍然工作,当我旋转屏幕的应用程序转到横向屏幕,我该如何解决这个问题?
答
你也应该继承UINavigationController
并把下面的代码在你的子类:
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// You do not need this method if you are not supporting earlier iOS Versions
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotate
{
return NO;
}
然后,初始化您的子类的实例:
MainVC *mainVC = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil];
MYSubclassedNavigationController *mainNav = [[MYSubclassedNavigationController alloc] initWithRootViewController:mainVC];
radioNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainNav animated:YES];
+0
谢谢!有效 – MTA
您需要检查每一次当前设备的方向或设备状态栏始发: - 请检查我的答案: - http://stackoverflow.com/questions/16710899/force-portrait-in-one-view-controller-makes-other-to-be-in-portrait -initially/16711127#16711127 –