iOS 屏幕旋转问题总结

1、UIDeviceOrientation 设备的物理方向

 

  • 简介

    UIDeviceOrientation即我们手持的移动设备的Orientation,是一个三围空间,故有六个方向:

  • UIDeviceOrientationUnknown,

      UIDeviceOrientationPortrait,            // Device oriented vertically, home button on the bottom

      UIDeviceOrientationPortraitUpsideDown,  // Device oriented vertically, home button on the top

      UIDeviceOrientationLandscapeLeft,       // Device oriented horizontally, home button on the right

      UIDeviceOrientationLandscapeRight,      // Device oriented horizontally, home button on the left

      UIDeviceOrientationFaceUp,              // Device oriented flat, face up

      UIDeviceOrientationFaceDown   

  • 获取

    通过[UIDevice currentDevice].orientation获取当前设备的方向

    当关闭了系统的横竖屏切换开关,即系统层级只允许竖屏时,再通过上述方式获取到的设备方向将只是UIDeviceOrientationPortrait。

  • UIDeviceOrientation是硬件设备的方向,是随着硬件自身改变的,只能取值,不能设置。

  • typedef enum {  
  •     UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,  
  •     UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,  
  •     UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,  
  •     UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft  
  • } UIInterfaceOrientation;  

 

  1. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
  2. {  
  3.     //宣告一個UIDevice指標,並取得目前Device的狀況  
  4.     UIDevice *device = [UIDevice currentDevice] ;   
  5.       
  6.     //取得當前Device的方向,來當作判斷敘述。(Device的方向型態為Integer)  
  7.     switch (device.orientation) {  
  8.         case UIDeviceOrientationFaceUp:  
  9.         NSLog(@"螢幕朝上平躺");  
  10.             break;  
  11.               
  12.         case UIDeviceOrientationFaceDown:  
  13.         NSLog(@"螢幕朝下平躺");  
  14.             break;  
  15.               
  16.         //系統無法判斷目前Device的方向,有可能是斜置   
  17.         case UIDeviceOrientationUnknown:  
  18.         NSLog(@"未知方向");  
  19.             break;  
  20.               
  21.         case UIDeviceOrientationLandscapeLeft:  
  22.         NSLog(@"螢幕向左橫置");  
  23.             break;  
  24.               
  25.         case UIDeviceOrientationLandscapeRight:  
  26.         NSLog(@"螢幕向右橫置");  
  27.             break;  
  28.               
  29.         case UIDeviceOrientationPortrait:  
  30.         NSLog(@"螢幕直立");  
  31.             break;  
  32.               
  33.         case UIDeviceOrientationPortraitUpsideDown:  
  34.         NSLog(@"螢幕直立,上下顛倒");  
  35.             break;  
  36.               
  37.         default:  
  38.         NSLog(@"無法辨識");  
  39.             break;  
  40.     }  
  41.   
  42.     // Return YES for supported orientations  
  43.     return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); // 只支持向左横向, YES 表示支持所有方向  
  • 2、UIInterfaceOrientation界面的显示方向

  •  

  • 简介

    UIInterfaceOrientation即我们看到的视图的Orientation,可以理解为statusBar所在的方向,是一个二维空间,有四个方向:

  • UIInterfaceOrientationUnknown            = UIDeviceOrientationUnknown,

        UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,

        UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,

        UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,

        UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft

  • http://www.cocoachina.com/ios/20180323/22747.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值