zoukankan      html  css  js  c++  java
  • ios的自动转屏

    在IOS6以前,设置转屏需要用到方法

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)x

    在6以后,取代它的是

    - (BOOL)shouldAutorotate

    - (NSUInteger)supportedInterfaceOrientations


    在论坛上看到个问题,如何用按钮控制自动转屏

    可以在相应的Controller中加入一个属性,一个BOOL型的变量autorotation


    应用的界面是


    然后再初始化的时候初始为YES,在自动转屏方法中return这个变量即可

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        self.autorotation = YES;
    }
    
    - (BOOL)shouldAutorotate
    {
        return self.autorotation;
    }
    
    - (NSUInteger)supportedInterfaceOrientations
    {
        return UIInterfaceOrientationMaskAll;
    }


    这个项目允许的转屏模式主要由项目信息中的设置决定的



    然后开始实现按钮的方法

    - (IBAction)changeFlag:(id)sender {
        if (_autorotation) {
            self.autorotation = NO;
            self.textLabel.text = @"Autorotation: No";
        } else {
            self.autorotation = YES;
            self.textLabel.text = @"Autorotation: Yes";
        }
    }


    这样就可以在点击按钮时更改是否允许转屏,以及Label中的text了。


    另外,在IOS6以后自动缩放的方框默认不显示了,是因为加入了autolayout且默认为勾选状态的

    取消勾选后Autosizing就显示出来了



  • 相关阅读:
    [Leetcode]@python 76. Minimum Window Substring
    [Leetcode]@python 75. Sort Colors
    HTNL表单
    第二天
    开学心德
    HTML表单
    网页制作
    2nd day
    开课心得
    CF10D/POJ2127 LCIS 题解
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3172188.html
Copyright © 2011-2022 走看看