单个APP页面支持屏幕旋转
1、info中支持所有的方向

2、APPDelega.h中添加属性
@property (nonatomic,assign) BOOL allowRotate;
APPdelegate.m中实现方法
//此方法会在设备横竖屏变化的时候调用
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (_allowRotate) {
return UIInterfaceOrientationMaskAll;
}else{
return UIInterfaceOrientationMaskPortrait;
}
}
3、在需要旋转的单个页面中添加
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
delegate.allowRotate = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
delegate.allowRotate = NO;
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]){
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation * invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = UIInterfaceOrientationPortrait;
[invocation setArgument:&val atIndex:];
[invocation invoke];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
// 屏幕从竖屏变为横屏时执行
NSLog(@"屏幕从竖屏变为横屏");
}else{
// 屏幕从横屏变为竖屏时执行
NSLog(@"屏幕从横屏变为竖屏");
}
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
// do something after rotation
}
后话
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]];
- (void)orientChange:(NSNotification *)notification {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
if (orientation == UIDeviceOrientationLandscapeLeft) {
NSLog(@"notification: 屏幕从竖屏变为横屏");
} else if (orientation == UIDeviceOrientationLandscapeRight) {
NSLog(@"notification: 屏幕从竖屏变为横屏");
} else if (orientation == UIDeviceOrientationPortrait) {
NSLog(@"notification: 屏幕从横屏变为竖屏");
}
}
单个APP页面支持屏幕旋转的更多相关文章
- app锁定屏幕方向,某一个界面支持屏幕旋转~
AppDelegate.h 加 @property (nonatomic, assign) BOOL allowRotation; Appdelegate.m加 -(NSUInteger)applic ...
- ios 不支持屏幕旋转
- (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; }
- iOS 让部分ViewController支持屏幕旋转
首先,在Xcode里设置整个项目支持的屏幕显示方向: 然后创建一个UINavigationController的子类,然后重载以下属性: 对于需要自定义屏幕方向的ViewController,重载这个 ...
- 【Android】[转] Android屏幕旋转使用OrientationEventListener的监听
说明 遇到一个奇葩的问题,我在使用onConfigChanged拦截屏幕的横竖屏旋转时,发现直接进行180度的横屏/竖屏转换居然没有反应!查找原因发现仅对landscape或者portrait状态有用 ...
- iOS实现屏幕旋转
iOS实现屏幕旋转有两种方式 1. 应用本身支持 2. 手动旋转UIView (这种方式我没找到旋转 系统控件的方法 如:键盘.导航.UIAlertView) 如果你只是要把竖屏的播放器,做成支持横屏 ...
- iOS学习笔记(3)— 屏幕旋转
一.屏幕旋转机制: iOS通过加速计判断当前的设备方向和屏幕旋转.当加速计检测到方向变化的时候,屏幕旋转的流程如下: 1.设备旋转时,系统接收到旋转事件. 2.系统将旋转事件通过AppDelegate ...
- H5项目常见问题及注意事项,视频全屏,定位,屏幕旋转和触摸,偏页面重构向 来源joacycode的github
Meta基础知识: H5页面窗口自动调整到设备宽度,并禁止用户缩放页面 //一.HTML页面结构 <meta name="viewport" content="wi ...
- iOS 实现单个页面支持横竖屏,其他页面只能竖屏
最近在自己的项目里面 有需要做一个需求 : app中某一个页面支持横竖屏, 而其他页面只能竖屏. 1 2 实现方法如下: 1 首先需要Xcode中选中支持的屏幕方向 2 Appdelegate中 . ...
- View页面内容的旋转,在某些情况下可替代屏幕旋转使用
这个是在做小秘书的体重曲线图的时候用到的,横排的时候可以多显示些内容,可是由于很多未知的冲突导至屏幕旋转起来非常麻烦,可用用旋转页面的内容来达到旋转屏幕的效果. 代码如下: //旋转90度 CGAff ...
随机推荐
- Android教材 | 第三章 Android界面事件处理(二)—— 杰瑞教育原创教材试读
编者按 JRedu 杰瑞教育原创系列教材将于年后与大家正式见面.为更好的借鉴读者意见,我们将会陆续地在博客园推出一系列教材试读.我们也热忱的欢迎广大博友与我们互动,提出宝贵意见. 本篇博客将推出教材 ...
- Hadoop:安装ftp over hdfs
https://blog.csdn.net/sptoor/article/details/11484855 https://blog.csdn.net/tengxing007/article/deta ...
- 安装loadrunner
Loadrunner安装具体解释 一 .下载篇. 我的下载地址是:http://pan.baidu.com/s/1c0IqAOC 程序4G多.非常大. 二. 安装篇 1.执行&qu ...
- MFC中的KillTimer
在Dialog中添加一个Timer. 用如下的代码停用一个Timer总是不好用: void CDialog2::OnTimer (UINT TimerVal) { ////////////////// ...
- PC 微信扫码登陆
目录 1.注册微信开发平台 2.微信开发平台添加网站应用 3.PC微信登录流程介绍 4.获取用户基本信息(UnionID机制) 1.注册微信开发平台 官网网址 自行注册,需要注意的是注册邮箱号不用与腾 ...
- 电子商务 B2C 结构图【转载+整理】
本文内容 商品展示 内容展示 订单确认 支付系统 用户中心 商品&促销 CRM 订单处理 WMS 采购管理 财务管理 报表管理 系统设置 WA系统 商品展示 按照 Ebay 内部分类,任何 ...
- @SuppressLint("NewApi")和@TargetApi()的区别
在Android代码中,我们有时会使用比我们在AndroidManifest中设置的android:minSdkVersion版本更高的方法,此时编译器会提示警告, 解决方法是在方法上加上@Suppr ...
- URAL 1224. Spiral (规律)
1224. Spiral Time limit: 1.0 second Memory limit: 64 MB A brand new sapper robot is able to neutrali ...
- 图解:如何在LINUX中安装VM-Tools
转自:http://blog.csdn.net/fu9958/article/details/4807000 使用VM安装虚拟系统,真的很方便.可以让个人轻松拥有一个网络,并包含有很多中系统. 因此, ...
- linux发送邮件的功能总结
今天添加了发送邮件的功能,总结一下,供以后参考: 1.直接使用管道发送邮件 echo "hello,this is the content of mail.welcome to www.mz ...