zoukankan      html  css  js  c++  java
  • 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;

    }

     
  • 相关阅读:
    软件工程第一次作业
    单调队列
    八皇后问题
    蓝桥-区间K大数查询
    putchar()和getchar()使用解析
    C++中的各种进制转换函数汇总及学习
    第五次团队作业
    第二次团队作业
    确定团队开发项目
    结对编程之设计电梯控制程序
  • 原文地址:https://www.cnblogs.com/xiaobaizhu/p/3435306.html
Copyright © 2011-2022 走看看