ios8中的UIScreen

Java代碼    收藏代碼
  1. let orientation: UIInterfaceOrientation = UIApplication.sharedApplication().statusBarOrientation  
  2.      println("Currently landscape: " + ((orientation == UIInterfaceOrientation.LandscapeLeft||orientation == UIInterfaceOrientation.LandscapeRight) ?"YES":"NO"))  
  3.      println("UIScreen.mainScreen().bounds: \(UIScreen.mainScreen().bounds)")  
  4.      println("UIScreen.mainScreen().applicationFrame: \(UIScreen.mainScreen().applicationFrame)")  

 在ios7中輸出:javascript

Currently landscape: NOhtml

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

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

Currently landscape: YESapp

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

 

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

 

在ios8中輸出:htm

Currently landscape: NOip

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

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)

 

結論:

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

爲了在ios8中獲得原來的效果能夠:

Java代碼    收藏代碼
  1. + (CGSize)screenSize {  
  2.     CGSize screenSize = [UIScreen mainScreen].bounds.size;  
  3.     return CGSizeMake(MIN(screenSize.width, screenSize.height), MAX(screenSize.width, screenSize.height));  
  4. }  

 

二、

在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

 

三、從UIScreen.mainScreen().applicationFrame輸出值看出,ios8默認橫屏statusbar是隱藏掉了。你能夠根據plist中

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

 

Java代碼    收藏代碼
  1. UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.None)  

 

Java代碼    收藏代碼
  1. override func prefersStatusBarHidden() -> Bool {  
  2.       return false  
  3.   
  4.   }  

顯示橫屏statusbar

相關文章
相關標籤/搜索