IOS疯狂基础之屏幕旋转控制,获得当前方向
获得当前屏幕方向
self.interfaceOrientation或[[UIApplication sharedApplication] statusBarOrientation]
if (self.interfaceOrientation==UIDeviceOrientationLandscapeRight) {
XXOO
}
不旋转,保持竖屏
//iOS 5 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {return (toInterfaceOrientation == UIInterfaceOrientationPortrait); } //iOS 6 - (BOOL)shouldAutorotate {return NO; } - (NSUInteger)supportedInterfaceOrientations {return UIInterfaceOrientationMaskPortrait; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {return UIInterfaceOrientationPortrait; }
始终保持横屏
//iOS 5 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {return (toInterfaceOrientation == self.preferredInterfaceOrientationForPresentation); } //iOS 6 - (BOOL) shouldAutorotate {return YES; } - (NSUInteger)supportedInterfaceOrientations {return UIInterfaceOrientationMaskLandscapeRight; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {return UIInterfaceOrientationLandscapeRight; }
在使用UINavigationController时发现,无论怎么设置上面方法的返回,都无法控制UINavigationController的旋转,这似乎是iOS的一个bug。但无论如何,以下是stackflow上面的一个解决方法:
1 @implementation UINavigationController (Rotation_IOS6) 2 -(BOOL)shouldAutorotate { 3 return [[self.viewControllers lastObject] shouldAutorotate]; 4 } 5 6 -(NSUInteger)supportedInterfaceOrientations { 7 return [[self.viewControllers lastObject] supportedInterfaceOrientations]; 8 } 9 10 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 11 return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 12 } 13 @end
屏幕旋转方法调用流程
要翻转的时候,首先响应的方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
return YES则支持翻转,NO则不支持。
紧接着
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
被调用。这个方法是发生在翻转开始之前。一般用来禁用某些控件或者停止某些正在进行的活动,比如停止视频播放。
再来是
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
这个方法发生在翻转的过程中,一般用来定制翻转后各个控件的位置、大小等。可以用另外两个方法来代替:willAnimateFirstHalfOfRotationToInterfaceOrientation:duration: 和 willAnimateSecondHalfOfRotationFromInterfaceOrientation:duration:
最后调用的是
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
这个方法发生在整个翻转完成之后。一般用来重新启用某些控件或者继续翻转之前被暂停的活动,比如继续视频播放
IOS疯狂基础之屏幕旋转控制,获得当前方向相关推荐
- IOS开发基础之屏幕组件适配添加约束
IOS开发基础之屏幕组件适配添加约束 使得横屏显示也能自动适配 对齐我们可以按住Ctrl键,把控件连线至view中 如果我们不小心添加错了.可以清除掉约束 具体约束可以在右边查看 by johnson ...
- IOS疯狂基础之GIF图片的显示
2019独角兽企业重金招聘Python工程师标准>>> IOS疯狂基础之GIF图片的显示 iPhone SDK提供了多种动画手段,UIView.UIImageView和CALayer ...
- IOS疯狂基础之键盘挡住输入框
一般来讲就是把整个屏幕上移么,不让键盘遮住 #pragma mark textField delegate 输入完后代理事件 - (void)textFieldDidEndEditing:(UITe ...
- IOS疯狂基础之UIImage
from: http://blog.csdn.net/wudizhukk/article/details/8989804 CGImage和CGImageRef这两个应当是用来重绘图形的类,它们在应用时 ...
- IOS疯狂基础之隐藏系统键盘
最简单的办法--设置为不可用: [dateTo setUserInteractionEnabled:NO];//不弹出键盘 [dateFrom setEnabled:NO];//不弹出键盘 [[[UI ...
- IOS疯狂基础之MessageUI—短信
我们知道可以使用这样的代码在iphone中发送短信:[[UIApplication sharedApplication] openURL:@"sms:12345678"]; 但这样 ...
- IOS开发基础之模拟科技头条项目案例32
IOS开发基础之模拟科技头条项目案例32 说说这个项目的技术要点核心 ,首先是异步网络请求,block的回调,sdWebImage的使用.各个控件的使用,NSDate日期的转换.自动适配屏幕工作,模型 ...
- iOS开发基础知识--碎片27
iOS开发基础知识--碎片27 1:iOS中的round/ceil/floorf extern float ceilf(float); extern double ceil(double); ext ...
- 【1】windows下IOS开发基础环境搭建
一.目的 本文的目的是windows下IOS开发基础环境搭建做了对应的介绍,大家可根据文档步骤进行mac环境部署: 二.安装虚拟机 下载虚拟机安装文件绿色版,点击如下文件安装 获取安装包: ...
最新文章
- 【JavaScript总结】JavaScript语法基础:数据类型
- 类的operator new与operator delete的重载
- NGUI_Texture
- python3 aes 报错 ValueError: Incorrect AES key length (95 bytes)的解决方案
- BDB c++例子,从源码编译到运行
- sublime Package Control 设备
- 谷歌深度学习四大教训:应用、系统、数据及原理(附数据集列表)
- How to Register COM in VS
- python cookie使用_Python使用cookielib模块操作cookie的实例教程
- 【转】ABP源码分析三十二:ABP.SignalR
- XCODE 出现 The operation couldn't be completed.(LaunchServicesError error 0.)错误修复
- .NetCore实践篇:成功解决分布式监控ZipKin聚合依赖问题(三)
- 论文笔记_S2D.39_2015-ICCV-条件随机场作为递归神经网络(CRF-RNN)
- nmake命令编译器的使用
- 【夜神模拟器运行app】uniapp将app运行到夜神模拟器
- javascript编写1加到100函数
- SIP-sipp的使用
- Crazy Engine 3.0(又名盘古引擎)的技术特性
- 我的QQ密保卡,不许偷看哦
- CSDN产品周报第19期|CodeChina正式更名为GitCode、不存在有效回答的免费提问也支持自主结题啦