iOS 控制屏幕旋转
在你想支持横竖屏的viewController里面重写两个方法:
1
2
3
4
5
6
7
8
9
10
11
|
// 支持设备自动旋转 - ( BOOL )shouldAutorotate { return YES; } // 支持横竖屏显示 - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } |
这样在这个viewController中就可以横竖屏切换了。
注意如果你 window 的 rootViewController 是一个navigationController,可能会出现以下问题:
1. 你的navigationController只支持竖屏,但是你push到了某个新的controller中,这个controller支持横竖屏,当你在新的controller中切换到横屏后(也有可能在切换到横屏然后pop回来后),这时候程序会闪退,因为你的navigationController不支持横屏。
2. 带有导航栏的 viewcontroller 无法进入此方法
- (BOOL)shouldAutorotate {
if (!isRotation) {
return YES;
} else {
return NO;
}
}
如果你想解决这个问题,就需要自己写一个UINavigationController的子类,在这个类中重写方法:
#import <UIKit/UIKit.h>
@interface UZUIAssetNavigationController : UINavigationController
@property (nonatomic, assign) BOOL isRotation;
@end
@implementation UZUIAssetNavigationController
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
- ( BOOL )shouldAutorotate { return [self.viewControllers.lastObject shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { return [self.viewControllers.lastObject supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation]; } |
然后用这个类去创建实例作为window的rootViewController,这样就可以避免这个问题了。
UZUIAssetNavigationController *assetGroupNavi = [[UZUIAssetNavigationController alloc]initWithRootViewController:assetGroupVc];
[self.viewController presentViewController:assetGroupNavi animated:YES completion:^{}];
iOS 控制屏幕旋转的更多相关文章
- iOS实现屏幕旋转
iOS实现屏幕旋转有两种方式 1. 应用本身支持 2. 手动旋转UIView (这种方式我没找到旋转 系统控件的方法 如:键盘.导航.UIAlertView) 如果你只是要把竖屏的播放器,做成支持横屏 ...
- ios实现屏幕旋转的方法
1.屏蔽AppDelegate下面的屏幕旋转方法 #pragma mark - 屏幕旋转的 //- (UIInterfaceOrientationMask)application:(UIApplica ...
- 监听iOS检测屏幕旋转状态,不需开启屏幕旋转-b
-(void)rotation_icon:(float)n { UIButton *history_btn= [self.view viewWithTag:<#(NSInteger)#>] ...
- 监听iOS检测屏幕旋转状态,不需开启屏幕旋转
-(void)rotation_icon:(float)n { UIButton *history_btn= [self.view viewWithTag:<#(NSInteger)#>] ...
- Flutter控制屏幕旋转
特定页面旋转屏幕很简单: SystemChrome.setPreferredOrientations([ ... ]); 数组中是您要支持的屏幕方向. 如果想在特定页面固定横屏, 您可以这样写: @o ...
- ios 关于屏幕旋转和屏幕晃动
内置加速计是智能手机最酷的特性之一,ios可以通过这个小设备知道用户握持手机的方式,以及用户是否移动了手机,ios使用加速计处理自动旋转,并且许多游戏都是用它作为控制机制,它还可以用于检测摇动和其他突 ...
- iOS强制屏幕旋转
/** 强制旋转屏幕为纵向 (注:这种方式 键盘不能旋转过来; iOS8.x下 UIAlterView旋转不过来 ) @return */ + (void)rotateOrientationPort ...
- 【iOS】屏幕旋转,屏幕自适应方向变化
1. iOS有四个方向的旋转,为了保证自己的代码能够支持旋转,我们必须首先处理一个函数: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInter ...
- IOS7学习之路八(iOS 禁止屏幕旋转的方法)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { retu ...
随机推荐
- netbeans tomcat
http://www.cnblogs.com/fengzy/archive/2013/05/18/3086371.html http://blog.csdn.net/xumengxing/articl ...
- Ajax的使用
Ajax是JQuery实现XMLHttpRequest的一种方式. 增加HTML5按钮,含有点击事件: <button type="button" class="b ...
- Centos7下搭建LAMP平台环境
1.启用Apache2 Centos7默认已经安装httpd服务,只是没有启动.如果你需要全新安装,可以yum install -y httpd 启动服务:systemctl start httpd. ...
- php正则
PHP代码 $str = preg_replace("/(<a.*?>)(.*?)(<\/a>)/", '\1<span class="li ...
- CMD代码页
不同字符编码在CMD模式下会出现乱码,需要使用 chcp 代码页 命令来更改代码页显示正常. UTF-8 65001 简体中文 936 437 美国 850 多语 ...
- Effective Java 学习笔记之所有对象都通用的方法
一.覆盖equals时请遵守通用约定 1.满足下列任何一个条件时,不需要覆盖equals方法 a.类的每个实例本质上都是唯一的.此时就是Object中equals方法所表达的含义. b.不关心类是否提 ...
- HDU 5053 the Sum of Cube
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5053 解题报告:用来陶冶情操的题,求a到b的三次方的和. #include<stdio.h> ...
- 下一代GNU/Linux显示服务Wayland 1.12正式发布
导读 最近,Bryce Harrington很高兴地宣布了“面向GNU/Linux操作系统的Wayland 1.12.0显示服务已正式发布”的消息.与它一同到来的,还有Weston 1.12.0合成器 ...
- linux各文件夹的作用
文章转载自:http://www.cnblogs.com/amboyna/archive/2008/02/16/1070474.html 精------------------------------ ...
- 剑指Offer 斐波那契数列
题目描述 大家都知道斐波那契数列,现在要求输入一个整数n,请你输出斐波那契数列的第n项. n<=39 思路: 不考虑递归 用递推的思路 AC代码: class Solution { public ...