Apple TV Tech Talks - Session 3 - tvOS
44:39
https://developer.apple.com/videos/play/techtalks-apple-tv/3/
ようやく具体的な実装方法についてのセッション。
tvOS向けアプリケーションではユーザーインタフェースとしてフォーカス指向インタフェースを採用している。これについてはデザインに関するセッションでも紹介された。
このセッションではフォーカス指向インタフェースの基本的な考え方、それを実現するためのフレームワークやクラス、そしてその具体的な実装方法について述べる。後半では、サンプルコードを使って実際に動かして説明しているのでわかりやすい。さらにデバッグ方法としてXcodeなどが備えている機能についても実際にデモしながら説明している。
tvOSで始めて導入されたフォーカス指向インタフェースを使う全てのプログラマが視聴すべきセッション。
なお、使われたサンプルコードは下記からダウンロードできる。
UIKit Catalog for tvOS (Sample Code)
https://developer.apple.com/library/tvos/samplecode/UICatalogFortvOS/Introduction/Intro.html
Build Requirements: Xcode 7.1 and tvOS 9.0 SDK or later
Runtime Requirements: tvOS 9.0 or later
[Siri Remote]
Apple TVはSiri Remoteを使って操作するので、それに適したインタフェースが必要。
[Focus Model]
フォーカスモデルがやっていること;
Interpret finger movement on remote
遠隔での指の動きを解釈して
Detemine the next view to be in focus
フォーカスで次のビューを決定する
Detect which views are focusable
ビューがフォーカス可能かどうか判定する。
Move focus
フォーカスを移動する
Animate focus changes
フォーカス変更アニメーション
Provide appearance for focused views
フォーカスされたビューを出現させる
Calculate and render parallax effect
パララックス効果を計算する
...
などなど
[Focus Engine]
上記すべてをプログラマが実装する必要はない。フォーカスエンジンを利用すればね。
Handles all user interaction in UIKit based apps
UIKitアプリですべてのユーザー操作を取り扱う
Tuned for Siri Remote
Siri Remoteでの操作に合わせる
Works with other remotes and game controllers
他のゲームコントローラなどにも対応可能
Consistent user experience across apps
アプリ間での操作性に一貫性を持たせる
[Overview]
[Basics]
右スワイプで右側の対象物にフォーカスを移動する。
[Focus API]
UIView
func canBecomeFocused() -> Bool
・フォーカス可能なビューかどうかを返す。
Initial Focus
UIFocusEnvironment
weak var preferredFocusedView: UIView? { get }
・初期フォーカスさせたいビューを指定する
preferred focus chain
[Table ad Collection Views]
Focusable rows and columns
tableView:canFocusRowAtIndexPath:
tableView:canFocusItemAtIndexPath:
Initial focus
indexPathForPreferredFocusedViewInTableView:
indexPathForPreferredFocusedViewInCollectionView:
remembersLastFocusedIndexPath
[Current Focus]
UIView
var focused: Bool { get }
UIScreen
weak var focusedView: UIView? { get }
プログラムから手動でフォーカスを変更することはできない。
ビューが削除された場合
ビューコントローラが出現/消滅した場合
データが再読込された場合
→ フォーカス更新要求
setNeedsFocusUpdate
[DEMO]
UIImageView
adjustsImageWhenAncestorFocused: Bool
[Implementing Focus Appearance]
[Responding to Focus Changes]
UIFocusEnvironemnt
- didUpdateFocusInContext: withAnimationCoordinator:
Delegate
coodinator.addCoordinatedAnimations({...}, completion: nil)
[Using focus guides]
vieDidLoad() フォーカスガイドを作成する
didUpdateFocusInContext: withAnimationCoordinator:中で更新する
focusGuide.prefferedFocusViewを設定
[Debugging focus]
_whyIsThisViewNotFocusable
カスタムQuickLook
[handling button presses]
UIGenstureRecognizer
- allowedPressTypes:
public enum UIPressType: Int
Select, Menu, PlayPause,
UpArrow, LeftArrow, RightArrow, DownArrow
tap, swipe, pan, long press
Low-Level event handling
UIResponder