[WWDC2014] About the Adaptive App.

[Memo] Building Adaptive Apps with UIKit, Session 216

Size class

在 iOS8 之前, 在開發過程中會有3個畫面的大小要去考慮, 並且還需要對 Protrait 跟 Landscape 做鄉對應的設計與調整.

而現在提出了一個新的概念 Size class 來描述現在 device 的 size(?) 與 oriention.

What’s the size class?

size class 顧名思義的就是用 width x height 的概念, 來描述現在的畫面呈現的大小; 並且使用下面的描述來敘述現在的畫面大小.

  • Compact (目前只有 iPhone 有使用到)
  • Regular

Apple 用兩個值來解釋現在顯示的 size; 已 iPhone 來說, 我們可以用 Compact x Regular 跟 Compact x Compact 來表示現在的 orientation 分別是 Protrait 以及 Landscope.

到這邊也許會有一點搞混, 也許會出現這樣的疑問 :
Q:在iPhone的時候, compact 的大小等於320嗎?
A:其實是不一定的, 這個數字是可以改變的.

Compact & Regular 與其說是一個數值, 其實應該要把它理解成一個狀態的敘述, 可以依照實際的需求去調整UIView / UIViewControllersize class; 即便在原本的iPhone Protrait(320x568) 的畫面下, 你也可以把寬度定義成是 Regular, 讓他顯示分割畫面.

UITraitCollection

Apple 使用 UITraitCollection 是用來表示現在 View 的 size class; 在 iOS8 中, UIView & UIViewController 都實作了一個新的 protocol UITraitEnvironment, 來描述這個底下的 view or subviews 的 traitCollection.

Asset Catalogs

Asset Catalogs 同使也增加了對應的功能, 讓畫面在不同的 sizs class 使用不同大小的圖片.

在 asset catalogs 的 inspector 中, 多出了 width & height 的選項, 可以依照實際的需求增加圖檔

關於 showViewController 的部份, 跑進去 UIViewController.h 看了一下, 比較像是最後找到了一樣有實作 showViewController:sender: 這個 method 的 UISplitViewController 物件, 讓splitViewController 去處理相關的事情.

小記

Adaptive 這個概念是想要讓的 device 可以輕易的改變/判斷 UITraitCollection 的內容進而 Customize layout, 在圖片的支援上也是挺到位; 在 IB 上更是支援各個 size 可以先共用基本的 autolayout 最後在個別 customize, 搭配 preivew 功能更可以馬上知道是否符合需求.

Comments