首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITabBarController演示模式AutoRotate问题

UITabBarController演示模式AutoRotate问题
EN

Stack Overflow用户
提问于 2013-05-27 20:52:21
回答 1查看 91关注 0票数 1

我有UITabBarController的SubClass来处理旋转问题:

代码语言:javascript
复制
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return YES;
}

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

-(BOOL)shouldAutorotate{
    return YES;
}

现在,我从tabbatcontroller中的一个UIViewController展示一个新的UIViewController

代码语言:javascript
复制
MainVC *mainVC = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil];
UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:mainVC];

radioNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainNav animated:YES];

在这个新的导航中,我想禁用自动旋转,只允许纵向旋转:

代码语言:javascript
复制
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate{
    return NO;
}

但是旋转仍然有效,当我旋转屏幕时,应用程序转到横向屏幕,我如何解决这个问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-05-27 21:36:44

您还应该创建UINavigationController的子类,并将以下代码放在子类中:

代码语言:javascript
复制
-(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;
}

然后,初始化一个子类的实例:

代码语言:javascript
复制
MainVC *mainVC = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil];
MYSubclassedNavigationController *mainNav = [[MYSubclassedNavigationController alloc] initWithRootViewController:mainVC];

radioNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainNav animated:YES];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16773646

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档