设备旋转的处理方法
来源:互联网 发布:淘宝怎么买彩票 编辑:程序博客网 时间:2024/05/18 23:13
加速计是整个IOS屏幕旋转的基础,依赖加速计,设备才可以判断出当前的设备方向,IOS系统共定义了以下七种设备方向:
typedef NS_ENUM(NSInteger, UIDeviceOrientation) { UIDeviceOrientationUnknown, UIDeviceOrientationPortrait, //面向设备的垂直,在底部的home键 UIDeviceOrientationPortraitUpsideDown, //面向设备的垂直,顶部的按钮 UIDeviceOrientationLandscapeLeft, // 设备水平方向的,右边的按钮 UIDeviceOrientationLandscapeRight, //面向设备的水平,左边的按钮 UIDeviceOrientationFaceUp, // Device oriented flat, face up UIDeviceOrientationFaceDown // Device oriented flat, face down};以及如下四种界面方向:
typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft};一、UIKit处理屏幕旋转的流程
当加速计检测到方向变化的时候,会发出 UIDeviceOrientationDidChangeNotification 通知,这样任何关心方向变化的view都可以通过注册该通知,在设备方向变化的时候做出相应的响应。
UIKit的相应屏幕旋转的流程如下:
1、设备旋转的时候,UIKit接收到旋转事件。
2、UIKit通过AppDelegate通知当前程序的window。
3、Window会知会它的rootViewController,判断该view controller所支持的旋转方向,完成旋转。
4、如果存在弹出的view controller的话,系统则会根据弹出的view controller,来判断是否要进行旋转。
二、UIViewController实现屏幕旋转
在响应设备旋转时,我们可以通过UIViewController的方法实现更细粒度的控制,当view controller接收到window传来的方向变化的时候,流程如下:
1、首先判断当前viewController是否支持旋转到目标方向,如果支持的话进入流程2,否则此次旋转流程直接结束。
2、调用 willRotateToInterfaceOrientation:duration:
方法,通知view controller将要旋转到目标方向。如果该viewController是一个container view controller的话,它会继续调用其content view controller的该方法。这个时候我们也可以暂时将一些view隐藏掉,等旋转结束以后在现实出来。
3、window调整显示的view controller的bounds,由于view controller的bounds发生变化,将会触发 viewWillLayoutSubviews 方法。这个时候
self.interfaceOrientation和statusBarOrientation方向还是原来的方向。
4、接着当前view controller的 willAnimateRotationToInterfaceOrientation:duration:
方法将会被调用。系统将会把该方法中执行的所有属性变化放到动animation block中。
5、执行方向旋转的动画。
6、最后调用 didRotateFromInterfaceOrientation:
方法,通知view controller旋转动画执行完毕。这个时候我们可以将第二部隐藏的view再显示出来。
整个响应过程如下图所示:
以上就是UIKit下一个完整的屏幕旋转流程,我们只需要按照提示做出相应的处理就可以完美的支持屏幕旋转。
- 设备旋转的处理方法
- 关于设备有效期的单片机处理方法
- android视频旋转处理方法
- onSaveInstanceState(...) 方法设备旋转数据保存
- IOS设备旋转的内部处理流程以及一些【优化建议】
- Android——处理设备旋转Activity销毁时临时数据丢失的问题
- 设备旋转
- 面试问题 activity生命周期,当设备旋转时android生命周期方法的调用顺序
- 关于adb无法识别android设备的处理方法
- Ubuntu下Android设备显示???的处理方法
- 设备配置(Device Configuration)改变时的处理方法
- 塑料造粒机风干设备风量不会集的处理方法
- 旋转的表示方法
- Android-四元数-控制VR设备的旋转
- UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法
- UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的用法
- 关于ios设备的旋转判断问题
- UIDeviceOrientation 和 UIInterfaceOrientation 设备旋转的方向
- 字符串最后一个单词的长度
- Bellman-Ford算法
- 注意检查变量的边界
- ListView的Item中带按钮以及按钮布局的显示与隐藏
- 转载收藏java佛祖注释
- 设备旋转的处理方法
- hdu 1018
- 指针函数与函数指针的区别
- android repo 建仓
- 子串和
- SDN你必须知道的十大问题——SDN有哪些开源项目?
- Convert Sorted List to Binary Search Tree
- 缓冲区溢出漏洞入门介绍
- A-star算法