代码处理iOS的横竖屏旋转

移动开发 iOS
在处理iOS横竖屏时,经常会和UIDeviceOrientation、UIInterfaceOrientation和UIInterfaceOrientationMask这三个枚举类型打交道,它们从不同角度描述了屏幕旋转方向。

一、监听屏幕旋转方向

在处理iOS横竖屏时,经常会和UIDeviceOrientation、UIInterfaceOrientation和UIInterfaceOrientationMask这三个枚举类型打交道,它们从不同角度描述了屏幕旋转方向。

1、UIDeviceOrientation:设备方向

iOS的设备方向是通过iOS的加速计来获取的。

1)iOS定义了以下七种设备方向

  1. typedef NS_ENUM(NSInteger, UIDeviceOrientation) { 
  2.  
  3.     UIDeviceOrientationUnknown,                 // 未知方向,可能是设备(屏幕)斜置 
  4.  
  5.     UIDeviceOrientationPortrait,                // 设备(屏幕)直立 
  6.  
  7.     UIDeviceOrientationPortraitUpsideDown,      // 设备(屏幕)直立,上下顛倒 
  8.  
  9.     UIDeviceOrientationLandscapeLeft,           // 设备(屏幕)向左横置 
  10.  
  11.     UIDeviceOrientationLandscapeRight,          // 设备(屏幕)向右橫置 
  12.  
  13.     UIDeviceOrientationFaceUp,                  // 设备(屏幕)朝上平躺 
  14.  
  15.     UIDeviceOrientationFaceDown                 // 设备(屏幕)朝下平躺 
  16.  
  17. };  

说明:UIDeviceOrientation参考home键方向,如:home方向在右,设备(屏幕)方向向左(UIDeviceOrientationLandscapeLeft)

2)读取设备方向

UIDevice单例代表当前的设备。从这个单例中可以获得的信息设备,如设备方向orientation。

  1. UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 

3)监听、处理和移除 设备方向改变的通知

当设备方向变化时候,发出UIDeviceOrientationDidChangeNotification通知;注册监听该通知,可以针对不同的设备方向处理视图展示。

  1. //开启和监听 设备旋转的通知(不开启的话,设备方向一直是UIInterfaceOrientationUnknown) 
  2.  
  3. if (![UIDevice currentDevice].generatesDeviceOrientationNotifications) { 
  4.  
  5.     [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
  6.  
  7.  
  8. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handleDeviceOrientationChange:) 
  9.  
  10.                                      name:UIDeviceOrientationDidChangeNotification object:nil]; 
  11.  
  12.   
  13.  
  14.   
  15.  
  16. //设备方向改变的处理 
  17.  
  18. - (void)handleDeviceOrientationChange:(NSNotification *)notification{ 
  19.  
  20.   
  21.  
  22.     UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 
  23.  
  24.     switch (ddeviceOrientation) { 
  25.  
  26.         case UIDeviceOrientationFaceUp: 
  27.  
  28.             NSLog(@"屏幕朝上平躺"); 
  29.  
  30.             break; 
  31.  
  32.   
  33.  
  34.         case UIDeviceOrientationFaceDown: 
  35.  
  36.             NSLog(@"屏幕朝下平躺"); 
  37.  
  38.             break; 
  39.  
  40.   
  41.  
  42.         case UIDeviceOrientationUnknown: 
  43.  
  44.             NSLog(@"未知方向"); 
  45.  
  46.             break; 
  47.  
  48.   
  49.  
  50.         case UIDeviceOrientationLandscapeLeft: 
  51.  
  52.             NSLog(@"屏幕向左横置"); 
  53.  
  54.             break; 
  55.  
  56.   
  57.  
  58.         case UIDeviceOrientationLandscapeRight: 
  59.  
  60.             NSLog(@"屏幕向右橫置"); 
  61.  
  62.             break; 
  63.  
  64.   
  65.  
  66.         case UIDeviceOrientationPortrait: 
  67.  
  68.             NSLog(@"屏幕直立"); 
  69.  
  70.             break; 
  71.  
  72.   
  73.  
  74.         case UIDeviceOrientationPortraitUpsideDown: 
  75.  
  76.             NSLog(@"屏幕直立,上下顛倒"); 
  77.  
  78.             break; 
  79.  
  80.   
  81.  
  82.         default
  83.  
  84.             NSLog(@"无法辨识"); 
  85.  
  86.             break; 
  87.  
  88.     } 
  89.  
  90.  
  91.   
  92.  
  93. //最后在dealloc中移除通知 和结束设备旋转的通知 
  94.  
  95. - (void)dealloc{ 
  96.  
  97.     //... 
  98.  
  99.     [[NSNotificationCenter defaultCenter]removeObserver:self]; 
  100.  
  101.     [[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications]; 

说明:手机锁定竖屏后,UIDeviceOrientationDidChangeNotification通知就失效了。

2、UIInterfaceOrientation:界面方向

界面方向是反应iOS中界面的方向,它和Home按钮的方向是一致的。

1)iOS定义了以下五种界面方向

  1. typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { 
  2.  
  3.     UIInterfaceOrientationUnknown            = UIDeviceOrientationUnknown,       //未知方向 
  4.  
  5.     UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,               //界面直立 
  6.  
  7.     UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,  //界面直立,上下颠倒 
  8.  
  9.     UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,   //界面朝左 
  10.  
  11.     UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft    //界面朝右 
  12.  
  13. } __TVOS_PROHIBITED;  

说明:从定义可知,界面方向和设别方向有对应关系,如界面的竖直方向就是 设备的竖直方向:UIInterfaceOrientationUnknown = UIDeviceOrientationUnknown

2)读取界面方向

UIInterfaceOrientation和状态栏有关,通过UIApplication的单例调用statusBarOrientation来获取

  1. UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 

3)监听、处理和移除 界面方向改变的通知

当界面方向变化时候,先后发出UIApplicationWillChangeStatusBarOrientationNotification和UIApplicationDidChangeStatusBarOrientationNotification通知;注册监听这两个通知,可以针对不同的界面方向处理视图展示。

  1. //以监听UIApplicationDidChangeStatusBarOrientationNotification通知为例 
  2.  
  3. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(handleStatusBarOrientationChange:) 
  4.  
  5.                                      name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; 
  6.  
  7.   
  8.  
  9.   
  10.  
  11. //界面方向改变的处理 
  12.  
  13. - (void)handleStatusBarOrientationChange: (NSNotification *)notification{ 
  14.  
  15.   
  16.  
  17.     UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 
  18.  
  19.     switch (interfaceOrientation) { 
  20.  
  21.   
  22.  
  23.         case UIInterfaceOrientationUnknown: 
  24.  
  25.             NSLog(@"未知方向"); 
  26.  
  27.             break; 
  28.  
  29.   
  30.  
  31.         case UIInterfaceOrientationPortrait: 
  32.  
  33.             NSLog(@"界面直立"); 
  34.  
  35.             break; 
  36.  
  37.   
  38.  
  39.         case UIInterfaceOrientationPortraitUpsideDown: 
  40.  
  41.             NSLog(@"界面直立,上下颠倒"); 
  42.  
  43.             break; 
  44.  
  45.   
  46.  
  47.         case UIInterfaceOrientationLandscapeLeft: 
  48.  
  49.             NSLog(@"界面朝左"); 
  50.  
  51.             break; 
  52.  
  53.   
  54.  
  55.         case UIInterfaceOrientationLandscapeRight: 
  56.  
  57.             NSLog(@"界面朝右"); 
  58.  
  59.             break; 
  60.  
  61.   
  62.  
  63.         default
  64.  
  65.             break; 
  66.  
  67.     } 
  68.  
  69.  
  70.   
  71.  
  72. //最后在dealloc中移除通知 
  73.  
  74. - (void)dealloc{ 
  75.  
  76.     //... 
  77.  
  78.     [[NSNotificationCenter defaultCenter]removeObserver:self]; 
  79.  
  80.     [[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications]; 
  81.  
  82.  

说明:手机锁定竖屏后,UIApplicationWillChangeStatusBarOrientationNotification和UIApplicationDidChangeStatusBarOrientationNotification通知也失效了。

3、UIInterfaceOrientationMask

UIInterfaceOrientationMask是为了集成多种UIInterfaceOrientation而定义的类型,和ViewController相关,一共有7种

1)iOS中的UIInterfaceOrientationMask定义

  1. typedef NS_OPTIONS(NSUInteger, UIInterfaceOrientationMask) { 
  2.  
  3.     UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait), 
  4.  
  5.     UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft), 
  6.  
  7.     UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight), 
  8.  
  9.     UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown), 
  10.  
  11.     UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), 
  12.  
  13.     UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown), 
  14.  
  15.     UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), 
  16.  
  17. } __TVOS_PROHIBITED; 

2)UIInterfaceOrientationMask的使用

在ViewController可以重写- (UIInterfaceOrientationMask)supportedInterfaceOrientations方法返回类型,来决定UIViewController可以支持哪些界面方向。

  1. //支持界面直立 
  2.  
  3. - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ 
  4.  
  5.     return UIInterfaceOrientationMaskPortrait; 
  6.  
  7.  

总结:UIDeviceOrientation(设备方向)和UIInterfaceOrientation(屏幕方向)是两个不同的概念。前者代表了设备的一种状态,而后者是屏幕为了应对不同的设备状态,做出的用户界面上的响应。在iOS设备旋转时,由UIKit接收到旋转事件,然后通过AppDelegate通知当前程序的UIWindow对象,UIWindow对象通知它的rootViewController,如果该rootViewController支持旋转后的屏幕方向,完成旋转,否则不旋转;弹出的ViewController也是如此处理。

二、视图控制器中旋转方向的设置

0、关于禁止横屏的操作(不建议)

比较常规的方法有两种。

方法1:在项目的General–>Deployment Info–>Device Orientation中,只勾选Portrait(竖屏)

 

勾选Portrait.png

方法2:Device Orientation默认设置,在Appdelegate中实现supportedInterfaceOrientationsForWindow:只返回UIInterfaceOrientationMaskPortraitt(竖屏)

  1. -  (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window  {   
  2.  
  3.      return UIInterfaceOrientationMaskPortrait;   
  4.  
  5.  

说明:极少的APP中所有界面都是竖屏的,因为总会有界面需要支持横屏,如视频播放页。所以不建议设置禁止APP页面横屏。

下面介绍如何让项目中的 视图控制器中旋转方向的设置

1、APP支持多个方向

 

APP支持多个方向.png

说明:如此,APP支持横屏和竖屏了,但是具体视图控制器支持的页面方向还需要进一步处理。由于不支持竖屏颠倒(Upside Down),即使设备上下颠倒,通过API也不会获得设备、屏幕上下颠倒方向的。

2、支持ViewController屏幕方向设置

1)关键函数

视图控制器支持的界面方向主要由以下三个函数控制

  1. //是否自动旋转,返回YES可以自动旋转,返回NO禁止旋转   
  2.  
  3. - (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;   
  4.  
  5.   
  6.  
  7. //返回支持的方向   
  8.  
  9. - (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;   
  10.  
  11.   
  12.  
  13. //由模态推出的视图控制器 优先支持的屏幕方向 
  14.  
  15. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;  

2) QSBaseViewController设置

  1. //QSBaseViewController.h 
  2.  
  3. @interface QSBaseController : UIViewController 
  4.  
  5.   
  6.  
  7. @end 
  8.  
  9.   
  10.  
  11. //QSBaseViewController.m 
  12.  
  13. @implementation QSBaseController 
  14.  
  15.   
  16.  
  17.   //#pragma mark - 控制屏幕旋转方法 
  18.  
  19. //是否自动旋转,返回YES可以自动旋转,返回NO禁止旋转 
  20.  
  21. - (BOOL)shouldAutorotate{ 
  22.  
  23.     return NO
  24.  
  25.  
  26.   
  27.  
  28. //返回支持的方向 
  29.  
  30. - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ 
  31.  
  32.     return UIInterfaceOrientationMaskPortrait; 
  33.  
  34.  
  35.   
  36.  
  37. //由模态推出的视图控制器 优先支持的屏幕方向 
  38.  
  39. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 
  40.  
  41.     return UIInterfaceOrientationPortrait; 
  42.  
  43.  
  44. @end  

说明1:QSBaseViewController默认不支持旋转,只支持 界面竖直方向,项目中的Controller都继承自QSBaseViewController,可以通过重写这三个方法来让Controller支持除竖屏之外的方向或旋转。

3) 在QSNavigationController设置

目标:通过QSNavigationController来push视图控制器时,把支持屏幕旋转的设置交给最新push进来([self.viewControllers lastObject])的viewController来设置。

  1. //QSNavigationController.h 
  2.  
  3. @interface QSNavigationController : UINavigationController 
  4.  
  5.   
  6.  
  7. @end 
  8.  
  9.   
  10.  
  11. //QSNavigationController.m 
  12.  
  13. @implementation QSNavigationController 
  14.  
  15.   
  16.  
  17. #pragma mark - 控制屏幕旋转方法 
  18.  
  19. - (BOOL)shouldAutorotate{   
  20.  
  21.     return [[self.viewControllers lastObject]shouldAutorotate]; 
  22.  
  23.  
  24.   
  25.  
  26. - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ 
  27.  
  28.     return [[self.viewControllers lastObject]supportedInterfaceOrientations]; 
  29.  
  30.  
  31.   
  32.  
  33. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 
  34.  
  35.     return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
  36.  
  37.  
  38. @end  

4) 在QSTabBarController设置

目标:TabBarController通常作为整个程序的rootViewController,UITabBar上面显示的每一个Tab都对应着一个ViewController;每点击一个Tab,出现的ViewController(self.selectedViewController)对屏幕旋转和支持方向的设置 交给其自身去控制。

  1. //QSTabBarController.h 
  2.  
  3. @interface QSTabBarController : UITabBarController 
  4.  
  5.   
  6.  
  7. @end 
  8.  
  9.   
  10.  
  11. //QSTabBarController.m 
  12.  
  13. @implementation QSTabBarController 
  14.  
  15.   
  16.  
  17. #pragma mark - 控制屏幕旋转方法 
  18.  
  19. - (BOOL)shouldAutorotate{ 
  20.  
  21.     return [self.selectedViewController shouldAutorotate]; 
  22.  
  23.  
  24.   
  25.  
  26. - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ 
  27.  
  28.     return [self.selectedViewController supportedInterfaceOrientations]; 
  29.  
  30.  
  31.   
  32.  
  33. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 
  34.  
  35.     return [self.selectedViewController preferredInterfaceOrientationForPresentation]; 
  36.  
  37.  
  38. @end  

三、屏幕旋转方向下的视图处理

1、屏幕旋转时,建议监听UIApplicationDidChangeStatusBarOrientationNotification

原因1:supportedInterfaceOrientations方法中最终返回的是 多个界面方向。

原因2(最重要的原因):我们真正要处理的是页面方向发生旋转UI的变化。而在设备的物理方向发生旋转的时候,如果此时当前控制器的页面并没有旋转,我们这时改变UI布局,可能就发生问题了。

2、屏幕的宽高处理

1)在iOS 8之后,当屏幕旋转的时候,[[UIScreen mainScreen] bounds]也发生了改变。如横屏时候的屏幕宽度 其实是竖屏的时候屏幕的高度。

2)我们处理视图布局时候,如果使用到屏幕的宽高,不要直接使用SCREEN_HEIGHT和SCREEN_WIDTH,而使用SCREEN_MIN和SCREEN_MAX

  1. #define SCREEN_HEIGHT CGRectGetHeight([[UIScreen mainScreen] bounds]) 
  2.  
  3. #define SCREEN_WIDTH  CGRectGetWidth([[UIScreen mainScreen] bounds]) 
  4.  
  5.   
  6.  
  7. #define SCREEN_MIN MIN(SCREEN_HEIGHT,SCREEN_WIDTH) 
  8.  
  9. #define SCREEN_MAX MAX(SCREEN_HEIGHT,SCREEN_WIDTH)  

说明:竖屏时候,宽是SCREEN_MIN,高是SCREEN_MAX;横屏时候,宽是SCREEN_MAX,高是SCREEN_MIN。

3、屏幕旋转下处理Demo

  1. //监听UIApplicationDidChangeStatusBarOrientationNotification的处理 
  2.  
  3. - (void)handleStatusBarOrientationChange: (NSNotification *)notification{ 
  4.  
  5.   
  6.  
  7.     UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 
  8.  
  9.     BOOL isLandscape = NO
  10.  
  11.     switch (interfaceOrientation) { 
  12.  
  13.   
  14.  
  15.         case UIInterfaceOrientationUnknown: 
  16.  
  17.             NSLog(@"未知方向"); 
  18.  
  19.             break; 
  20.  
  21.   
  22.  
  23.         case UIInterfaceOrientationPortrait: 
  24.  
  25.         case UIInterfaceOrientationPortraitUpsideDown: 
  26.  
  27.             isLandscape = NO
  28.  
  29.             break; 
  30.  
  31.   
  32.  
  33.         case UIInterfaceOrientationLandscapeLeft: 
  34.  
  35.         case UIInterfaceOrientationLandscapeRight: 
  36.  
  37.             isLandscape = YES; 
  38.  
  39.             break; 
  40.  
  41.   
  42.  
  43.         default
  44.  
  45.             break; 
  46.  
  47.     } 
  48.  
  49.     if (isLandscape) { 
  50.  
  51.         self.tableView.frame = CGRectMake(0, 0, SCREEN_MAX, SCREEN_MIN - 44); 
  52.  
  53.     }else
  54.  
  55.         self.tableView.frame = CGRectMake(0, 0, SCREEN_MIN, SCREEN_MAX - 64); 
  56.  
  57.     } 
  58.  
  59.   
  60.  
  61.     [self.tableView reloadData]; 
  62.  
  63.  

说明:当然也可以选择使用Masonry这样优秀的AutoLayout布局第三方库来处理,storyBoard来布局次之。

4、屏幕旋转下处理Demo效果图

 

竖屏下效果.png

 

横屏下效果.png

5、屏幕旋转处理的建议

1)旋转前后,view当前显示的位置尽量不变

2)旋转过程中,暂时界面操作的响应

3)视图中有tableview的话,旋转后,强制 [tableview reloadData],保证在方向变化以后,新的row能够充满全屏。

四、强制横屏

APP中某些页面,如视频播放页,一出现就要求横屏。这些横屏页面或模态弹出、或push进来。

1、模态弹出ViewController情况下 强制横屏的设置

  1. //QSShow3Controller.m 
  2.  
  3. - (BOOL)shouldAutorotate{ 
  4.  
  5.     return NO
  6.  
  7.  
  8.   
  9.  
  10. - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ 
  11.  
  12.     return UIInterfaceOrientationMaskLandscapeRight; 
  13.  
  14.  
  15.   
  16.  
  17. - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 
  18.  
  19.     return UIInterfaceOrientationLandscapeRight; 
  20.  
  21.  
  22.   
  23.  
  24. //模态弹出 
  25.  
  26. QSShow3Controller *vc = [[QSShow3Controller alloc]init]; 
  27.  
  28. [self presentViewController:vc animated:YES completion:nil];  

说明:这种情况比较简单处理。

2、push推入ViewController情况下 强制横屏的设置

  1. //QSShow4Controller.m 
  2.  
  3. -(void)viewWillAppear:(BOOL)animated{ 
  4.  
  5.   
  6.  
  7.    [super viewWillAppear:animated]; 
  8.  
  9.    [self setInterfaceOrientation:UIInterfaceOrientationLandscapeRight]; 
  10.  
  11.  
  12.   
  13.  
  14. //强制转屏(这个方法最好放在BaseVController中) 
  15.  
  16. - (void)setInterfaceOrientation:(UIInterfaceOrientation)orientation{ 
  17.  
  18.   
  19.  
  20.     if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { 
  21.  
  22.         SEL selector  = NSSelectorFromString(@"setOrientation:"); 
  23.  
  24.         NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; 
  25.  
  26.         [invocation setSelector:selector]; 
  27.  
  28.         [invocation setTarget:[UIDevice currentDevice]]; 
  29.  
  30.         // 从2开始是因为前两个参数已经被selector和target占用 
  31.  
  32.         [invocation setArgument:&orientation atIndex:2]; 
  33.  
  34.         [invocation invoke]; 
  35.  
  36.     } 
  37.  
  38.  
  39.   
  40.  
  41. //必须返回YES 
  42.  
  43. - (BOOL)shouldAutorotate{ 
  44.  
  45.     return YES; 
  46.  
  47.  
  48.   
  49.  
  50. - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ 
  51.  
  52.     return UIInterfaceOrientationMaskLandscapeRight; 
  53.  
  54.  
  55.   
  56.  
  57. //Push推入 
  58.  
  59. QSShow4Controller *vc = [[QSShow4Controller alloc]init]; 
  60.  
  61. [self.navigationController pushViewController:vc animated:YES];  

说明:苹果不允许直接调用setOrientation方法,否则有被拒的风险;使用NSInvocation对象给[UIDevice currentDevice]发消息,强制改变设备方向,使其页面方向对应改变,这是苹果允许的。

五、其他

1、 APP启动时,手机横屏下,首页UI(该页面只支持竖屏)出错(add by 2017/6/20)

  1. //设置设置状态栏竖屏 
  2.  
  3.   [[UIApplication sharedApplication]setStatusBarOrientation:UIInterfaceOrientationPortrait];  

以上详细源码参考:QSRotationScreenDemo

https://github.com/buaa0300/QSKitDemo/tree/master/QSRotationScreenDemo 

责任编辑:庞桂玉 来源: iOS大全
相关推荐

2013-08-21 11:15:54

iOS横竖屏方案

2013-05-23 10:51:28

Android开发移动开发横竖屏切换

2012-05-22 14:26:15

XNA 横竖屏设置

2011-07-29 10:21:03

iPad 横竖屏 切换

2016-09-18 10:51:01

JavascriptHtml5移动应用

2010-01-25 15:23:12

Android横竖屏切

2017-11-20 11:07:23

Selection代码逻辑分支

2023-11-02 09:42:21

iOS屏幕旋转

2011-06-08 15:05:43

J2ME

2013-04-09 10:03:29

iOS6.0旋转兼容

2012-12-24 08:54:47

iOSUnity3D

2012-01-10 09:32:12

iOS 5.1设备四核处理器

2013-07-29 05:04:19

Cocos2dx横屏竖

2022-01-25 10:11:10

红绿屏苹果BUG

2013-07-29 04:24:40

iOS开发学习ViewControl

2017-12-20 16:58:49

iOS离屏渲染屏幕渲染

2017-11-16 15:21:06

代码taste方法

2012-02-02 16:35:42

Silverlight低级别触屏处理

2011-07-25 16:31:51

iOS XML 文件

2014-05-09 12:59:26

iOS移动互联网
点赞
收藏

51CTO技术栈公众号