zoukankan      html  css  js  c++  java
  • iOS界面设置竖屏,个别界面强制横屏

    项目需要,只有某个界面需要横屏显示,其它全只支持竖屏显示即可,网上资料很多,但是试过都不好用,最后发现是因为我的项目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;
    }
    

     亲测好用~

  • 相关阅读:
    [php-src]一个Php扩展的结构
    告别2015,迎来2016
    [JS]应用splice删除多元素时出现的坑
    [Ng]Angular应用点概览
    [MongoDB]Mongodb攻略
    GNU M4
    [Linux]服务管理:RPM包, 源码包
    [Shell]条件判断与流程控制:if, case, for, while, until
    [Shell]字符截取命令:cut, printf, awk, sed
    [Shell]正则表达式与通配符
  • 原文地址:https://www.cnblogs.com/luleigreat/p/5743677.html
Copyright © 2011-2022 走看看