博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(转)iOS 某个界面支持旋转
阅读量:6955 次
发布时间:2019-06-27

本文共 1403 字,大约阅读时间需要 4 分钟。

原文地址: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

你可能感兴趣的文章
力扣算法题—051N皇后问题
查看>>
Elementary Methods in Number Theory Exercise 1.5.11
查看>>
化一阶线性方程为恰当方程
查看>>
服务器使用ssh秘钥登录并禁止密码登录
查看>>
django基础知识~forms钩子
查看>>
javascript预解释中的机制
查看>>
正则表达式pattern的匹配格式
查看>>
JDOM
查看>>
MySQL 最基本的SQL语法/语句
查看>>
洛谷 P2661 信息传递 Label:并查集||强联通分量
查看>>
Linux下搭建ftp服务器(转载)
查看>>
hadoop之 HDFS-Hadoop存档
查看>>
搭建时间服务器
查看>>
php 多进程 父进程的阻塞与非阻塞
查看>>
asp.net core mvc ActionFilterAttribute 获取自动定义Attribute
查看>>
sealed、new、virtual、abstract与override 趣解
查看>>
[bzoj 4650][NOI 2016]优秀的拆分
查看>>
crossplatform---Nodejs in Visual Studio Code 08.IIS
查看>>
OGNL表达式入门
查看>>
Java 诊断工具 Arthas 教程学习笔记
查看>>