(转)iOS 某个界面支持旋转

原文地址:http://blog.csdn.net/littleSun_zheng/article/details/50748698

步骤1、

设置 targets——>general——>device Orientation

步骤2、

 <1>在 AppDelegate.h 里面 加一个属性 
 @property (nonatomic,assign)BOOL allowRotation;//这个属性标识屏幕是否允许旋转
复制代码
<2>在 AppDelegate.m 里面
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if (self.allowRotation) {//当允许时,支持所有方向
        return UIInterfaceOrientationMaskAll;
    }
    //否则 就只有竖屏
    return UIInterfaceOrientationMaskPortrait;
}
复制代码

步骤3、 在你想要支持 旋转的控制器 需要导入#import "AppDelegate.h"

 - (void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];

        self.navigationController.navigationBarHidden = YES;

    //改变AppDelegate的appdelegete.allowRotation属性
     AppDelegate *appdelegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
    appdelegete.allowRotation = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;

    AppDelegate *appdelegete = (AppDelegate *)[UIApplication sharedApplication].delegate;
    appdelegete.allowRotation = NO;
}

复制代码

步骤4、 但在横屏播放的状态下 直接返回上个控制器(pop)的时候. 发现那个控制器也是横屏的,假设上个控制器名字叫SimpleVC,在SimpleVC.m里添加

//屏幕方向操作
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}
复制代码

转载于:https://juejin.im/post/5a3782b5f265da4322414c99

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值