ios8中的UIScreen,ios8UIScreen

來源:互聯網
上載者:User

ios8中的UIScreen,ios8UIScreen
Java代碼  

  • let orientation: UIInterfaceOrientation = UIApplication.sharedApplication().statusBarOrientation  
  •      println("Currently landscape: " + ((orientation == UIInterfaceOrientation.LandscapeLeft||orientation == UIInterfaceOrientation.LandscapeRight) ?"YES":"NO"))  
  •      println("UIScreen.mainScreen().bounds: \(UIScreen.mainScreen().bounds)")  
  •      println("UIScreen.mainScreen().applicationFrame: \(UIScreen.mainScreen().applicationFrame)")  
  •    let orientation: UIInterfaceOrientation = UIApplication.sharedApplication().statusBarOrientation        println("Currently landscape: " + ((orientation == UIInterfaceOrientation.LandscapeLeft||orientation == UIInterfaceOrientation.LandscapeRight) ?"YES":"NO"))        println("UIScreen.mainScreen().bounds: \(UIScreen.mainScreen().bounds)")        println("UIScreen.mainScreen().applicationFrame: \(UIScreen.mainScreen().applicationFrame)")

     在ios7中輸出:

    Currently landscape: NO

    UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)

    UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)

    Currently landscape: YES

    UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)

     

    UIScreen.mainScreen().applicationFrame: (20.0,0.0,300.0,568.0)

     

    在ios8中輸出:

    Currently landscape: NO

    UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)

    UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)

    Currently landscape: YES

    UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0)

    UIScreen.mainScreen().applicationFrame: (0.0,0.0,568.0,320.0)

     

    結論:

    1、在ios7中UIScreen.mainScreen().bounds是固定不變的值,在ios8中他的值是隨橫豎屏改變的!

    為了在ios8中得到原來的效果可以:

    Java代碼  
  • + (CGSize)screenSize {  
  •     CGSize screenSize = [UIScreen mainScreen].bounds.size;  
  •     return CGSizeMake(MIN(screenSize.width, screenSize.height), MAX(screenSize.width, screenSize.height));  
  • }  
  • + (CGSize)screenSize {    CGSize screenSize = [UIScreen mainScreen].bounds.size;    return CGSizeMake(MIN(screenSize.width, screenSize.height), MAX(screenSize.width, screenSize.height));}

     

    2、

    在ios8中增加了2個屬性:

    nativeBounds :  螢幕像素,不隨橫豎平改變的!

    nativeScale   :1(non retina)/2(retina)/3(retina hd)

    https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScreen_Class/index.html#//apple_ref/occ/instp/UIScreen/nativeBounds

    ios8輸出:

    Currently landscape: YES

    UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0)

    UIScreen.mainScreen().applicationFrame: (0.0,20.0,568.0,300.0)

    UIScreen.mainScreen().nativeBounds: (0.0,0.0,640.0,1136.0)

    UIScreen.mainScreen().nativeScale: 2.0

    Currently landscape: NO

    UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)

    UIScreen.mainScreen().applicationFrame: (0.0,20.0,320.0,548.0)

    UIScreen.mainScreen().nativeBounds: (0.0,0.0,640.0,1136.0)

     

    UIScreen.mainScreen().nativeScale: 2.0

     

    3、從UIScreen.mainScreen().applicationFrame輸出值看出,ios8預設橫屏statusbar是隱藏掉了。你可以根據plist中

    View controller-based status bar appearance的值的不同來用       

     

    Java代碼  
  • UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)  
  • UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)

     

    Java代碼  
  • override func prefersStatusBarHidden() -> Bool {  
  •       return false  
  •   
  •   }  
  •   override func prefersStatusBarHidden() -> Bool {        return false     }

    顯示橫屏statusbar

    相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.