WWDC 15 Session 107 学习笔记

By on

Session 107 - What’s New in Cocoa Touch

Looking Back

在 iOS 9 誕生之前,其實蘋果就已經做了很多基礎建設性的鋪墊了:

  • iOS 6:引入了 AutoLayout
  • iOS 7:Dynamic Type,系统可以设置 app 内的字体大小
  • iOS 8:Adaptivity,可以在 Xcode 下看到不同的 Size Classes,以及对于不同的 iPhone/iPad 设备适配的 View Controllers 还有 Action Sheets

Now in iOS 9

于是来到了 iOS 9 的时代,新增了两个特性:Multitasking(多任务)Picture-in-Picture(画中画)。接下来就是具体介绍了 Cocoa Touch 下的新的特性。

  1. AutoLayout:

    • 新增 UILayoutGuide 類來實現過去需要使用不可見的 Dummy View 來作為補充對齊元素的功能。例如:
    UILayoutGuide *space1 = [[UILayoutGuide alloc] init];
         [self.view addLayoutGuide:space1];
         UILayoutGuide *space2 = [[UILayoutGuide alloc] init];
         [self.view addLayoutGuide:space2];
     
         [space1.widthAnchor constraintEqualToAnchor:space2.widthAnchor].active = YES;
         [self.saveButton.trailingAnchor constraintEqualToAnchor:space1.leadingAnchor].active = YES;
         [self.cancelButton.leadingAnchor constraintEqualToAnchor:space1.trailingAnchor].active = YES;
         [self.cancelButton.trailingAnchor constraintEqualToAnchor:space2.leadingAnchor].active = YES;
         [self.clearButton.leadingAnchor constraintEqualToAnchor:space2.trailingAnchor].active = YES;
    
  2. UIStackView

    引入 UIStackView 來創建流式的佈局。

  3. Shortcuts Bar

    iPad 上輸入法預測的一行在 iOS 9 上同時提供了快捷操作。通過 UITextInputAssistantItem 來給 Shortcuts Bar 上的左右兩個圖標組(leadingBarButtonGroupstrailingBarButtonGroups)來添加新的按鈕。

  4. Storyboard

    多 Storyboard 支持。

  5. Right-to-Left

    對阿拉伯語等「從右向左」閱讀的語言進行了支持。對不同的 Controller、Gesture 甚至 UIImage 都可以選擇顯示的方向。在 iOS 9 下,UIView 也增加了 UISemanticContentAttribute 這樣一個屬性來判斷視圖是否會遵循顯示的方向規則(默認是 UISemanticContentAttributeUnspecified)。

  6. Accessibility:吐槽一下國內的公司很少有接觸這一塊啊…

  7. Text Editing Gestures:可以在鍵盤上利用手勢來實現對指針的移動、文本的選擇的功能。

  8. Keyboard Commands(Cheatsheet):連接外接鍵盤的時候長按 調出。

  9. Touch Events:優化了觸控的延遲,並且使用了觸控預測(Touch Prediction)。

New in Kits

  1. UIKit Dynamics:
    • 支持了非矩形碰撞效果
    • 物體關聯時的行為(UIAttachmentBehavior)
    • 在不同力場下的行為(UIFieldBehavior)
    • 其他的視覺效果(Visual Effects in Spotlight)
  2. API Optimizations for Swift:在 Session 106 下有詳細解釋。

  3. Notifications:通知顯示的方式(Behavior)。

  4. Safari:App 內可以使用 SFSafariViewController 來提供原生瀏覽器的支持。

  5. Extension:
    • VPN Tunnel provider
    • App proxy provider
    • Filter control provider
    • Safari
      • Shared links
      • Content blocking
    • Spotlight
      • Indexing of application data
      • Index maintenance
    • Audio Units

    前面幾點感覺 SS 和 Adblock 即將走進 iOS 9 中。最後的 Audio Units 要提一下,開發者可以使用系統中不支持的視頻或者音頻播放格式了。

  6. Contacts:新的 API,一筆帶過了。

  7. Wallet and PassKit:為  Pay 鋪路。

  8. Core Location:提供了單次獲得地點的 API,使用 CLLocationManager 中的 requestLocation 函數。

  9. MapKit:提供 3D 俯視視圖,可以顯示交通情況以及指南針等功能。

  10. HealthKit:和 watchOS 2 適配,增加了數(xing)據(sheng)類(huo)型和調用 API 接口。

  11. ResearchKit:適配 iPad 並且提供了照片捕獲的功能。

  12. HomeKit:
    • Detailed change notifications
    • Predefined scenes
    • Expanded trigger support
    • watchOS 2 support
    • Remote access

    智能家電的春天就要到了!

  13. CloudKit:更加優惠的價格和服務,Web 端的支持。

  14. UIDocument:Open in place。

  15. On Demand Resources:詳細在 Session 105 中。
    • Hosted on the App Store
    • Asset Tags
    • App Slicing
  16. ReplayKit

  17. SpriteKit

  18. SceneKit

  19. GamePlayKit:編寫遊戲的 AI 和規則系統。

  20. watchOS 2