iOS 7 到iOS 8 的適配

在iOS 8中,[UIScreen bounds] 、[UIScreen applicationFrame] 、Status bar、Keyboard這些frame都是根據設備真實方向來返回frame的,而在iOS 7中,不過是橫屏還是豎屏,iOS總是返回豎屏的frame,如以下輸出:

iOS 7:

  1. 豎屏:  
  2. UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)  
  3. 橫屏:  
  4. UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)  
iOS 8:

  1. 豎屏:  
  2. UIScreen.mainScreen().bounds: (0.0,0.0,320.0,568.0)  
  3. 橫屏:  
  4. UIScreen.mainScreen().bounds: (0.0,0.0,568.0,320.0)  
這就對某些支持橫屏的App造成了困擾,其實也只需要加兩個宏或者改造一下就行了:

  1. #define SCREEN_WIDTH        (getScreenSize().width)  
  2. #define SCREEN_HEIGHT       (getScreenSize().height)  
  1. CGSize getScreenSize() {  
  2.     CGSize screenSize = [UIScreen mainScreen].bounds.size;  
  3.     if ((NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) &&  
  4.         UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {  
  5.         return CGSizeMake(screenSize.height, screenSize.width);  
  6.     }  
  7.     return screenSize;  
  8. }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章