以上具体源码参考:QSRotationScreenDemo
在处理iOS反正屏时,经常会和UIDeviceOrientation、UIInterfaceOrientation和UIInterfaceOrientationMask这三个列举类型打交道,它们大年夜不合角度描述了屏幕扭转偏向。
1、UIDeviceOrientation:设备偏向
iOS的设备偏向是经由过程iOS的加快计来获取的。
1)iOS定义了以下七种设备偏向
- typedef NS_ENUM(NSInteger, UIDeviceOrientation) {
- UIDeviceOrientationUnknown, // 未知偏向,可能是设备(屏幕)斜置
- UIDeviceOrientationPortrait, // 设备(屏幕)竖立
- UIDeviceOrientationPortraitUpsideDown, // 设备(屏幕)竖立,高低顛倒
- UIDeviceOrientationLandscapeLeft, // 设备(屏幕)向左横置
- UIDeviceOrientationLandscapeRight, // 设备(屏幕)向右橫置
- UIDeviceOrientationFaceUp, // 设备(屏幕)朝上平躺
- UIDeviceOrientationFaceDown // 设备(屏幕)手下平躺
- };
解释:UIDeviceOrientation参考home键偏向,如:home偏向在右,设备(屏幕)偏向向左(UIDeviceOrientationLandscapeLeft)
2)攫取设备偏向
UIDevice单例代表当前的设备。大年夜这个单例中可以获得的信息设备,如设备偏向orientation。
- UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
3)监听、处理和移除 设备偏向改变的通知
当设备偏向变更时刻,发出UIDeviceOrientationDidChangeNotification通知;注册监听该通知,可以针对不合的设备偏向处理视图展示。
解释:手机锁定竖屏后,UIDeviceOrientationDidChangeNotification通知就掉效了。
2、UIInterfaceOrientation:界面偏向
界面偏向是反竽暌功iOS中界面的偏向,它和Home按钮的偏向是一致的。
1)iOS定义了以下五种界面偏向
- typedef NS_ENUM(NSInteger, UIInterfaceOrientation) {
- UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown, //未知偏向
- UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, //界面竖立
- UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, //界面竖立,高低倒置
- UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, //界面朝左
- UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft //界面朝右
- } __TVOS_PROHIBITED;
解释:大年夜定义可知,界面偏向和设别偏向有对应关系,如界面的竖直偏向就是 设备的竖直偏向:UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown
2)攫取界面偏向
- //开启和监听 设备扭转的通知(不开启的话,设备偏向一向是UIInterfaceOrientationUnknown)
推荐阅读
近年来,Python 在数据科学行业扮演着越来越重要的角色。是以,我根据比来的应用体验,在本文中列出了对数据科学家、工程师们最有效的那些库。因为这些库都开源了,我们大年夜Github上惹人>>>详细阅读
本文标题:代码处理iOS的横竖屏旋转
地址:http://www.17bianji.com/lsqh/36388.html
1/2 1