码迷,mamicode.com
首页 > 移动开发 > 详细

iOS界面设置竖屏,个别界面强制横屏

时间:2016-08-06 12:57:12      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

项目需要,只有某个界面需要横屏显示,其它全只支持竖屏显示即可,网上资料很多,但是试过都不好用,最后发现是因为我的项目UIViewController外层是UINavigationVeiwController,只在UIViewController重载supportedInterfaceOrientations与shouldAutorotate 方法是不行的。

下面说明具体设置步骤:(参考http://www.cocoachina.com/bbs/read.php?tid-244095.html

Step 1:Info.plist中设置Supported interface orientations 为所有支持的方向,我是这样设置的:

    技术分享

Step 2:在自定义的navigationViewController中添加属性:

@property (nonatomic, assign) BOOL supportLandscape;

 初始化:

 

- (id)init
{
	if (self = [super init])
	{
		[self setup];
	}
	
	return self;
}

- (void)setup
{
	//其他设置
        ...
    	self.supportLandscape = NO;
}

  

 重载supportedInterfaceOrientations方法:

- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController{
    if(self.supportLandscape){
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeRight;
    }else{
        return UIInterfaceOrientationMaskPortrait;
    }
}

Step 3:我的项目中所有viewController都是由navigationController控制的,所以,只需要在需要支持横屏的viewController中进行设置就好了:

-(void) viewDidAppear:(BOOL)animated{
    [SlideNavigationController sharedInstance].supportLandscape = YES;
}

-(void) viewDidDisappear:(BOOL)animated{
    [SlideNavigationController sharedInstance].supportLandscape = NO;
}

 亲测好用~

iOS界面设置竖屏,个别界面强制横屏

标签:

原文地址:http://www.cnblogs.com/luleigreat/p/5743677.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!