iOS 8 牛刀小試


iOS 8 牛刀小試

 

1、UIWindow的bounds發生變化(Window本身發生了旋轉)

  iOS 7之前Window的bounds不會隨着方向而變化,但是到了iOS 8以后,隨着設備方向的旋轉,window.bounds.size.width和window.bounds.size.height也會相應發生變化。

  做個很簡單的測試,代碼如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];
    
    return YES;
}

- (void)orientationChanged:(NSNotification*)noti {
    
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
    NSString *orientationDes = nil;
    switch (orientation) {
        case UIDeviceOrientationLandscapeLeft:
            orientationDes = @"UIInterfaceOrientationLandscapeRight";
            break;
        case UIDeviceOrientationLandscapeRight:
            orientationDes = @"UIInterfaceOrientationLandscapeLeft";
            break;
        case UIDeviceOrientationPortrait:
            orientationDes = @"UIInterfaceOrientationPortrait";
            break;
        case UIDeviceOrientationPortraitUpsideDown:
            orientationDes = @"UIInterfaceOrientationPortraitUpsideDown";
            break;
        default:
            orientationDes = @"";
            break;
    }
    
    NSLog(@"system ver: %@, \rorientaion: %@, \rwindow bounds: %@",
          [UIDevice currentDevice].systemVersion,
          orientationDes,
          NSStringFromCGRect(self.window.bounds));
}

  示例代碼很簡單,新建一個工程,然后在delegate中直接添加以上代碼即可。

  iOS 8上運行結果為:

2014-06-04 09:26:32.016 SviOS8[4143:61114] system ver: 8.0, 
orientaion: UIInterfaceOrientationLandscapeRight, 
window bounds: {{0, 0}, {320, 480}}
2014-06-04 09:26:34.788 SviOS8[4143:61114] system ver: 8.0, 
orientaion: UIInterfaceOrientationPortrait, 
window bounds: {{0, 0}, {480, 320}}
2014-06-04 09:26:35.791 SviOS8[4143:61114] system ver: 8.0, 
orientaion: UIInterfaceOrientationLandscapeLeft, 
window bounds: {{0, 0}, {320, 480}}
2014-06-04 09:26:47.468 SviOS8[4143:61114] system ver: 8.0, 
orientaion: UIInterfaceOrientationPortraitUpsideDown, 
window bounds: {{0, 0}, {480, 320}}

  iOS 7及之前的版本運行結果為:

2014-06-04 09:39:00.527 SviOS8[4380:70b] system ver: 7.0.3, 
orientaion: UIInterfaceOrientationLandscapeRight, 
window bounds: {{0, 0}, {320, 480}}
2014-06-04 09:39:00.895 SviOS8[4380:70b] system ver: 7.0.3, 
orientaion: UIInterfaceOrientationPortrait, 
window bounds: {{0, 0}, {320, 480}}
2014-06-04 09:39:01.225 SviOS8[4380:70b] system ver: 7.0.3, 
orientaion: UIInterfaceOrientationLandscapeLeft, 
window bounds: {{0, 0}, {320, 480}}
2014-06-04 09:39:11.004 SviOS8[4380:70b] system ver: 7.0.3, 
orientaion: UIInterfaceOrientationPortraitUpsideDown, 
window bounds: {{0, 0}, {320, 480}}

  通過對比我們可以清晰的看到iOS 8中UIWindow在處理旋轉時策略的變更,雖然會因為與之前的版本不同導致現有項目布局存在的bug,但是可以看到iOS 8中的處理方式更加符合我們的預期,在豎向的時候我們就獲取到width < height, 在橫向則是 width > height,這個符合所見即所得的原則。

  題外話,不管是iOS 7還是之前的版本,以及最新出的iOS 8,所有的ViewController的bounds都是正確的,所以只需要堅持一個原則“所有布局都是基於VC.view.bounds布局,那么你的App的顯示就一切正常。”

  當然如果你有任何View不受VC的管理,直接添加到window上,那么就悲劇了,請添加代碼去單獨支持。

  好消息:所有基於iOS 7 SDK編譯的程序,window的機制還遵循原來的機制,也就是說可以平滑過度到iOS系統,所有界面布局一切正常。不得不說蘋果這一點做的真贊,不愧是一家偉大的公司。

  

2、安裝iOS 8 beta版本注意事項

  官方給出的注意事項地址: http://adcdownload.apple.com//wwdc_2014/ios_8_beta_wg4j9a/ios_beta_software_installation_guide.pdf

  主要意思是:

  1)升級后不可降級,so升級之前還是想清楚

  2)做好備份工作,因為畢竟是beta版本,可能有些不穩定的地方,可能在升級過程中會丟失數據

  3)支持設備:

  iPhone 4s, iPhone 5, iPhone 5c, iPhone 5s, iPod touch (5th gen),
  iPad 2, iPad with Retina display, iPad Air and iPad mini

  4)目前只支持開發者預覽

  5)反饋問題地址如下: https://developer.apple.com/bug-reporting/

  

3、QR Code支持

  Core Image framework (CoreImage.framework)新增了如下API:

  • 支持自定義imageKernels

  • 增加矩形檢測和圖片中二維碼識別功能

  詳細文檔: Core Image Reference Collection.

 

4、UITableView的Edit模式異常

  iOS 8預覽版中TableView進入edit模式以后,調用reloadData以后tableView中cell的編輯模式的樣式顯示會出現問題(編輯空間消失),不知道后面蘋果的正式發布的iOS 8版本中會不會解決這個問題。

 

5、View Debugger

  xCode6中新增加了UI調試神器View Debugger,該工具可以在調試中繪制出當前View層級的3D顯示,如下圖所示:

  

View debugging. Using the view debugger makes debugging an app’s appearance is as easy as debugging lines of code. A single button click pauses your running app and “explodes” the paused UI into a 3D rendering, separating each layer of a stack of views. Using the view debugger makes it immediately obvious why an image may be clipped and invisible, and the order of the graphical elements becomes clear. By selecting any view, you can inspect the details by jumping to the relevant code in the assistant editor source view. The view debugger also displays Auto Layout constraints, making it easy to see where conflicts cause problems.

  官方文檔中解釋的很清楚,有了該工具以后遇到View被覆蓋,超出父View等原因引起的無法響應用戶事件的問題可以輕松解決了,真是開發者的一大福音。

 

注:本篇文章,持續更新,歡迎一起討論iOS 8

  如果覺得本文幫到了你,請推薦給身邊的朋友

  轉載請著名出處,有什么問題歡迎留言

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM