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就显示出来了



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值