iOS 屏幕旋转控制
来源:互联网 发布:淘宝上的服装利润多少 编辑:程序博客网 时间:2024/05/16 07:39
今天主要给大家讲一下在iOS开发中怎样控制屏幕的旋转。
在iOS6之前的版本中,我们经常用 shouldAutorotateToInterfaceOrientation: 方法来控制一个UIViewController的旋转方向支持,如:
<span style="font-size:18px;">- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ return (interfaceOrientation == UIInterfaceOrientationPortrait);}</span>
但是在iOS6.0中这个方法被废弃了。
<span style="font-size:18px;">// Applications should use supportedInterfaceOrientations and/or shouldAutorotate..- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation NS_DEPRECATED_IOS(2_0, 6_0) __TVOS_PROHIBITED;</span>
新的控制方式是通过两个方法一起来控制的
<span style="font-size:18px;">// New Autorotation support.- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;- (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;// Returns interface orientation masks.- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;</span>
通过实践得出结论,如果window的根视图是一个UINavigationController对象,对屏幕旋转方向的控制方法如下:
<span style="font-size:18px;">- (BOOL)shouldAutorotate { return self.topViewController.shouldAutorotate; } - (NSUInteger)supportedInterfaceOrientations { return self.topViewController.supportedInterfaceOrientations; } </span>然后在添加的UIViewController中添加一下代码控制屏幕的旋转(支持所有版本)
<span style="font-size:18px;">- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (BOOL)shouldAutorotate{ return NO;}- (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait;}</span>
<span style="font-size:18px;"></span>
<span style="font-size:18px;"></span>
<span style="font-size:18px;">开启全部方向支持 </span>
<span style="font-size:18px;">- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; } -(BOOL)shouldAutorotate { return YES; } </span>
0 0
- [IOS] 屏幕旋转控制
- ios控制屏幕旋转
- iOS 屏幕旋转控制
- iOS 屏幕旋转控制
- iOS控制屏幕旋转
- iOS 屏幕自动旋转控制
- iOS控制屏幕旋转方向
- IOS 屏幕旋转控制详解-特酷吧
- iOS 屏幕旋转控制(iOS 9.1适用)
- android 屏幕旋转控制
- Android屏幕旋转控制
- 屏幕的旋转控制
- ios 6 的变化 与 旋转屏幕控制
- IOS疯狂基础之屏幕旋转控制,获得当前方向
- IOS疯狂基础之屏幕旋转控制,获得当前方向
- IOS疯狂基础之屏幕旋转控制,获得当前方向
- IOS&Android通用屏幕控制(移动旋转缩放)
- IOS&Android通用屏幕控制(移动旋转缩放)
- could not find a getter for ... in class ... 异常的原因解析
- IOS加减选择器
- layout下activity_main.xml无法显示界面出现This version of the rendering library is more recent than your versi
- linux中查看nginx、apache、php、mysql配置文件路径的方法
- linux守护进程及其创建
- iOS 屏幕旋转控制
- iOS 打包错误 command..exit code 127...
- 《软件架构设计》学习笔记--3--软件架构视图
- Volley图片加载并加入缓存处理
- WebViewJavascriptBridge 解析
- IOS开发之—程序截图
- 关于手机连不上拼命循环弹出“Connection attempts: x远程主机强迫关闭了一个现有的连接 ”的解决办法
- hash表海量查找字符串(java版)
- 时间序列完全教程(R)