• ios6,ios7强制转屏


    在父视图控制器里面写如下代码

    -(void)setViewOrientation:(UIInterfaceOrientation )orientation
    {
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
            [[UIDevice currentDevice] performSelector:@selector(setOrientation:)
                                           withObject:(id)orientation];
        }
        [UIViewController attemptRotationToDeviceOrientation];//这句是关键
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    
    -(BOOL)shouldAutorotate
    {
        return YES;
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return toInterfaceOrientation==UIInterfaceOrientationPortrait;
    }

    在子视图控制器的加入,这里子视图控制器要横屏

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear :YES];
        [self setViewOrientation:UIInterfaceOrientationLandscapeRight];
    }
    //重写下面子类的方法

    - (NSUInteger) supportedInterfaceOrientations{

        returnUIInterfaceOrientationMaskLandscapeRight;

    }

     

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation NS_DEPRECATED_IOS(2_0, 6_0){

        return toInterfaceOrientation == UIInterfaceOrientationLandscapeRight;

    }

     
  • 相关阅读:
    Apache mod_rewrite
    vim 常用设置
    ssh 和 scp 命令访问非默认22端口。
    gulp常用插件
    gulp+Babel 搭建ES6环境
    ES6类与模块
    Autoprefixer处理CSS3属性前缀
    js模块方案
    ES6转码器babel的使用
    window.history.pushState与ajax实现无刷新更新页面url
  • 原文地址:https://www.cnblogs.com/xiaobaizhu/p/3435306.html
Copyright © 2020-2023  润新知