作家
登录

代码处理iOS的横竖屏旋转

作者: 来源: 2017-07-25 13:05:41 阅读 我要评论

        case UIDeviceOrientationPortrait: 
  •  
  •             NSLog(@"屏幕竖立"); 
  •  
  •             break; 
  •  
  •   
  •  
  •         case UIDeviceOrientationPortraitUpsideDown: 
  •  
  •             NSLog(@"屏幕竖立,高低顛倒"); 
  •  
  •             break; 
  •  
  •   
  •  
  •         default
  •  
  •             NSLog(@"无法辨识"); 
  •  
  •             break; 
  •  
  •     } 
  •  
  •  
  •   
  •  
  • //最后在dealloc中移除通知 和停止设备扭转的通知 
  •  
  • - (void)dealloc{ 
  •  
  •     //... 
  •  
  •     [[NSNotificationCenter defaultCenter]removeObserver:self]; 
  •  
  •     [[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications]; 
  • UIInterfaceOrientation和状况栏有关,经由过程UIApplication的单例调用statusBarOrientation来获取

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

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

    解释:手机锁定竖屏后,UIApplicationWillChangeStatusBarOrientationNotification和UIApplicationDidChangeStatusBarOrientationNotification通知也掉效了。

    3、UIInterfaceOrientationMask

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

    1)iOS中的UIInterfaceOrientationMask定义

    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.  

        推荐阅读

        2017,最受欢迎的 15 大 Python 库有哪些?

      近年来,Python 在数据科学行业扮演着越来越重要的角色。是以,我根据比来的应用体验,在本文中列出了对数据科学家、工程师们最有效的那些库。因为这些库都开源了,我们大年夜Github上惹人>>>详细阅读


      本文标题:代码处理iOS的横竖屏旋转

      地址:http://www.17bianji.com/lsqh/36388.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)