Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Developing for tvOS and working with focus engine

Developing for tvOS and working with focus engine

Talk from CocoaHeads Kraków #20, 12.05.2016

Michał Ciuba

May 12, 2016
Tweet

More Decks by Michał Ciuba

Other Decks in Programming

Transcript

  1. Agenda • Apple TV - introduction • Developing for tvOS:

    the good, the bad and the ugly • Focus engine • Demo
  2. Apple TV • A set-top box and a simple game

    console • Siri remote (touch surface, microphone, accelerometer), optional game controllers • A8 processor, 2 GB RAM, 32/64 GB storage • 24 million to sell in 2016 (estimated)
  3. tvOS 9.x • SDK available since Apple TV 4th gen

    (late 2015) • Based on iOS 9 • Apps: native (Objective-C / Swift) or TVML + JS
  4. The good • Very similar to iOS (most of the

    frameworks are available) • UIKit components work well with new input methods (remote, voice) • New parallax effects, easy to implement in apps
  5. The good • All the new iOS 9 APIs are

    there • No need to worry about backward compatibility (at least now) • One screen size (1920 x 1080 @1x), no rotation • Human Interface Guidelines give good hints for UI design
  6. The bad • No Safari, WebKit, web views • Unavailable

    frameworks (MapKit, Photos, Social, Multipeer Connectivity, HomeKit…) • Only few gestures available (tap, swipe, long press, pan)
  7. The bad • The device is always connected, so… •

    App size is limited (200 MB). On-demand resources have to be used to download more assets • No local persistent storage, app data can be deleted between launches. Use CloudKit instead
  8. Focus engine • No touch screen, interface is controlled indirectly

    • Remote: swipe up/down/left/right + tap (no „multitouch”) • Menu button works as „back”button • UI elements become focused (highlighted) as the user navigates through them
  9. Focus engine • Some items are focusable (UIButton), some not

    (UILabel) • UIView has canBecomeFocused property • You can support focus in custom views • Focus updates are initiated by the user • You can also request focus update programatically
  10. UIFocusEnvironment • Implemented by UIViewController, UIView • Indirect control over

    the focus engine (you can’t set the focused view explicitly) • Setting initial focus • Responding to focus changes (animations!)
  11. UIFocusEnvironment weak public var preferredFocusedView: UIView? { get } public

    func setNeedsFocusUpdate() public func updateFocusIfNeeded() public func shouldUpdateFocusInContext(context: UIFocusUpdateContext) -> Bool public func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator)
  12. UIFocusEnvironment weak public var preferredFocusedView: UIView? { get } public

    func setNeedsFocusUpdate() public func updateFocusIfNeeded() public func shouldUpdateFocusInContext(context: UIFocusUpdateContext) -> Bool public func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator)
  13. UIFocusEnvironment weak public var preferredFocusedView: UIView? { get } public

    func setNeedsFocusUpdate() public func updateFocusIfNeeded() public func shouldUpdateFocusInContext(context: UIFocusUpdateContext) -> Bool public func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator)
  14. UIFocusGuide • Inherits from UILayoutGuide • „represents an invisible, focusable

    region that can redirect focus movement to other views” • Useful in custom views • Unavailable in Interface Builder
  15. Parallax effect • set adjustsImageWhenAncestorFocused on UIImageView • works with

    layered and plain images (also app icons) • public var focusedFrameGuide: UILayoutGuide { get }