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

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

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

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

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;
}

 亲测好用~

相关文章:

  • 2021-04-26
  • 2021-10-31
  • 2021-07-18
  • 2021-10-19
  • 2018-08-23
  • 2021-08-07
  • 2021-09-07
猜你喜欢
  • 2021-09-26
  • 2021-12-25
  • 2021-08-12
  • 2021-11-20
  • 2021-11-16
  • 2021-12-23
  • 2021-10-19
相关资源
相似解决方案