首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >自动旋转iOS 8导航控制器

自动旋转iOS 8导航控制器
EN

Stack Overflow用户
提问于 2015-06-15 12:12:54
回答 2查看 1.3K关注 0票数 2

我有一些viewControllers,它们由UINavigationController (push和pop)管理。我想把不同的viewControllers限制在不同的orientations上,比如第一个应该只在Portrait中,第二个在portrait中,第三个在landscape中,第四个可以是portraitlandscape。我在ViewController上设置了一个来自storyBoardisInitialViewController

代码语言:javascript
运行
复制
- (BOOL) shouldAutorotate{
return NO;

}

没有任何问题,但是当我将navigation controller (通过push和pop管理这四个视图)设置为来自storyBoardisInitialViewController时,这个函数不再被调用,现在是autoratates。如何阻止使用此autorotating作为isInitialViewController的这些视图。我使用以下函数取决于它是哪个ViewController

代码语言:javascript
运行
复制
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIDeviceOrientationPortrait);//choose portrait or landscape}

- (BOOL) shouldAutorotate{
return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
//return UIInterfaceOrientationMaskLandscape;
return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{ 
//    return UIInterfaceOrientationLandscapeLeft |
//    UIInterfaceOrientationLandscapeRight;
return UIInterfaceOrientationPortrait;
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-15 12:59:43

只需子类UINavigationController和重写适当的方法:

.h文件:

代码语言:javascript
运行
复制
@interface CustomUINavigationController : UINavigationController
@property   BOOL canRotate;
@end

.m文件:

代码语言:javascript
运行
复制
@implementation CustomUINavigationController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (BOOL)shouldAutorotate
{
    return self.canRotate;
}
@end
票数 1
EN

Stack Overflow用户

发布于 2015-06-15 12:25:41

如果你为UINavigation控制器设定目标C类并覆盖接口定位方法.我认为你试图控制自动旋转。

目标C类http://rypress.com/tutorials/objective-c/categories

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30844898

复制
相关文章

相似问题

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