•focus interaction in tvos 11...sound identifier description custom sound identifier (e.g....

76
#WWDC17 © 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple. Matt Ricketson, UIKit Engineer Jon Staff, UIKit Engineer Focus Interaction in tvOS 11 Session 224 App Frameworks

Upload: others

Post on 04-Jul-2020

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

#WWDC17

© 2017 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.

Matt Ricketson, UIKit Engineer Jon Staff, UIKit Engineer

•Focus Interaction in tvOS 11 • Session 224

App Frameworks

Page 2: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•New features and enhancements •Support for SceneKit •New debugging tools

Page 3: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•Review

Page 4: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Environment

Item Item

Environment

Review Focus environment hierarchy

Common Parent Environment

Root Environment

Page 5: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Environment

Item Item

Common Parent Environment

Environment

UIFocusItem

Review Focus environment hierarchy

Root Environment

Page 6: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Environment

Item Item

Environment

UIFocusItem

UIFocusEnvironment

Review Focus environment hierarchy

Common Parent Environment

Root Environment

Page 7: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Environment

Item Item

Root Environment

Common Parent Environment

Environment

Review Focus environment hierarchy

Page 8: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

User-initiated focus movement

Programmatic focus updates • Requested via setNeedsFocusUpdate

Review Types of focus updates

Page 9: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Update

Review Focus updates

Page 10: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Update

func didUpdateFocus(in:with:)

UIFocusEnvironment

Review Focus updates

Page 11: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•Focus Update Notifications

Page 12: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Updates

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Update

func didUpdateFocus(in:with:)

UIFocusEnvironment

Page 13: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Updates

Other Object

?

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Update

func didUpdateFocus(in:with:)

UIFocusEnvironment

Page 14: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Sent on every focus update

Sent after calling didUpdateFocus(in:with:) on all relevant focus environments

User info dictionary includes both the context and animation coordinator

Focus Update Notifications

static let UIFocusDidUpdate: Notification.Name

NEW

Page 15: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Update Notifications User info keys

UIFocusUpdateContextKey Provides the UIFocusUpdateContext instance that describes the update.

UIFocusUpdateAnimationCoordinatorKey Provides the UIFocusAnimationCoordinator instance associated with the update.

NEW

Page 16: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Sent when the user tries, but fails, to move focus in a certain direction

Not sent for programmatic focus updates that fail

Also provides a UIFocusUpdateContext instance

Use for providing helpful feedback to the user

Focus Update Notifications

static let UIFocusMovementDidFail: Notification.Name

NEW

Page 17: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•Protocol Extensions •UIFocusEnvironment and UIFocusItem

Page 18: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Protocol Extensions UIFocusItem

Check if an item is currently focused:

let isFocused = item.isFocused

NEW

Page 19: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Protocol Extensions Focus environment containment

Check if a focus environment contains another environment:

if environment1.contains(environment2) { // do something }

NEW

Page 20: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

// MyViewController.h

override func didUpdateFocus(in context: UIFocusUpdateContext,

with coordinator: UIFocusAnimationCoordinator) {

super.didUpdateFocus(in: context, with: coordinator)

if let nextFocusedItem = context.nextFocusedItem, self.contains(nextFocusedItem) { // focus is inside the view controller }

}

Page 21: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Jon Staff, UIKit Frameworks Engineer

•Focus Animation Enhancements

Page 22: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Animations Review

open class UIFocusAnimationCoordinator : NSObject {

open func addCoordinatedAnimations(_ animations: (() -> Void)?, completion: (() -> Void)? = nil)

...

}

Use the coordination API for matching system animations

Provided whenever a focus update occurs

Page 23: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Animations Review

UIKit manages focus animations

Animation duration is influenced by the speed of focus movement • Quicker movements have quicker animations • Slower movements have slower animations • Animations for off-screen items are delayed

Page 24: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Animations Review

Focusing animations are quicker and more prominent

Un-focusing animations are slower and subtler

Page 25: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Animations Review

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Moves

func didUpdateFocus(in:with:)

UIFocusEnvironment

Page 26: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Animations Review

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Moves

func didUpdateFocus(in:with:)

UIFocusEnvironmentUn-focusing Animations

func addCoordinatedAnimations(_:completion:)

Page 27: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Animations Review

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Moves

func didUpdateFocus(in:with:)

UIFocusEnvironmentFocusing Animations

func addCoordinatedAnimations(_:completion:)

Page 28: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Targeted Coordinated Animations Review

NEW

Page 29: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Targeted Coordinated Animations Review

open class UIFocusAnimationCoordinator : NSObject {

open func addCoordinatedAnimations(_ animations: (() -> Void)?, completion: (() -> Void)? = nil)

open func addCoordinatedFocusingAnimations(_ animations: ((UIFocusAnimationContext) -> Void)?, completion: (() -> Void)? = nil)

open func addCoordinatedUnfocusingAnimations(_ animations: ((UIFocusAnimationContext) -> Void)?, completion: (() -> Void)? = nil)

}

NEW

Page 30: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

func addCoordinatedUnfocusingAnimations(_:completion:)

Un-focusing Animations

Focus Animations New API

func addCoordinatedFocusingAnimations(_:completion:)

Focusing Animations

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Moves

NEW

Page 31: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•Demo •Targeted coordinated animations

Page 32: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Timing information provided by UIFocusAnimationContext

Targeted Coordinated Animations New API

public protocol UIFocusAnimationContext : NSObjectProtocol {

/// The duration of the main animations in seconds.

public var duration: TimeInterval { get }

}

NEW

Page 33: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {

coordinator.addCoordinatedFocusingAnimations({ animationContext in let duration = animationContext.duration / 2.0

UIView.animate(withDuration: duration, delay: duration, // start at the halfway point options: [.overrideInheritedDuration], animations: { // some animation }) })}

Page 34: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {

coordinator.addCoordinatedFocusingAnimations({ animationContext in let duration = animationContext.duration / 2.0

UIView.animate(withDuration: duration, delay: duration, // start at the halfway point options: [.overrideInheritedDuration], animations: { // some animation }) })}

Page 35: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {

coordinator.addCoordinatedFocusingAnimations({ animationContext in let duration = animationContext.duration / 2.0

UIView.animate(withDuration: duration, delay: duration, // start at the halfway point options: [.overrideInheritedDuration], animations: { // some animation }) })}

Page 36: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {

coordinator.addCoordinatedFocusingAnimations({ animationContext in let duration = animationContext.duration / 2.0

UIView.animate(withDuration: duration, delay: duration, // start at the halfway point options: [.overrideInheritedDuration], animations: { // some animation }) })}

Page 37: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

UIFocusAnimationContext

Better non-UIKit support

Consistent feel for focus interaction across frameworks

override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) { let node = myNode coordinator.addCoordinatedFocusingAnimations({ animationContext in let fadeAction = SKAction.fadeAlpha(to: 0.5, duration: animationContext.duration) node.run(fadeAction) }) }

Page 38: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Summary

Use the existing API when targeting isn’t needed

Use the new coordination APIs for targeting animations

Use the animation context for timing information

Page 39: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•Custom Focus Sounds

Page 40: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Sounds

Volume adjustments based on speed • Faster movements have quieter sounds • Slower movements have louder sounds

Panning adjustments based on location • Items on the right side of the screen will pan right • Items on the left side of the screen will pan left

Page 41: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds New API

Play custom sounds when focus movement occurs

Opt out of UIKit-played sounds

NEW

Page 42: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds New API

Register a sound with an identifier

Provide a sound identifier during a focus update

Sound matching the identifier is played

NEW

Page 43: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Class method on UIFocusSystem

Custom Focus Sounds New API

open class UIFocusSystem : NSObject {

/// Registers a sound file for a given identifier. open class func register(_ soundFileURL: URL,

forSoundIdentifier identifier: UIFocusSoundIdentifier)

}

NEW

Page 44: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds New API

Global registration

Register only once per sound identifier

Register early

Accepts standard iOS sound file formats

NEW

Page 45: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds New API

Optional method on UIFocusEnvironment

public protocol UIFocusEnvironment : NSObjectProtocol {

...

optional public func soundIdentifierForFocusUpdate(in context: UIFocusUpdateContext) -> UIFocusSoundIdentifier?

...

}

NEW

Page 46: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds New API

NEW

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Update

func soundIdentifierForFocusUpdate(in:)

UIFocusEnvironment

Page 47: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds New API

NEW

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Update

func soundIdentifierForFocusUpdate(in:)

UIFocusEnvironment

Page 48: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds New API

NEW

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Update

func soundIdentifierForFocusUpdate(in:)

UIFocusEnvironment

Page 49: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds New API

NEW

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Update

func soundIdentifierForFocusUpdate(in:)

UIFocusEnvironment

Page 50: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds New API

NEW

Environment

Previous Item Next Item

Root Environment

Common Parent Environment

Environment

Focus Update

func soundIdentifierForFocusUpdate(in:)

UIFocusEnvironment

Page 51: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Sound Identifier Description

Custom Sound Identifier (e.g. .myCustomIdentifier)

Plays the sound registered with this sound identifier.

.default Explicitly force the default UIKit sound to play.

.none Opt out of UIKit-played sounds for this focus update.

Custom Focus Sounds New API

NEW

Page 52: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds New API

Conditionally playing a custom sound

override func soundIdentifierForFocusUpdate(in context: UIFocusUpdateContext) -> UIFocusSoundIdentifier? { if let nextFocusedItem = context.nextFocusedItem, soundEnabledEnvironment.contains(nextFocusedItem) { return myCustomSoundIdentifier } return nil}

NEW

Page 53: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds Opting out of sounds

Users expect focus movements to play sounds

Only opt out of focus sounds if your users expect it • i.e. user-toggled sound settings in a game

Respect user device settings for navigation sounds

Page 54: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Custom Focus Sounds Best practices

Custom sounds should enhance the user experience

Differentiate between different elements • i.e. Size or element type

Page 55: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Matt Ricketson, UIKit Frameworks Engineer

•Support for SceneKit

Page 56: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Item Types tvOS 9

UIFocusEnvironment

UIView

Page 57: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Item Types tvOS 10

UIFocusItem

UIView

UIFocusEnvironment

SKNode

Page 58: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Item Types tvOS 11

UIFocusItem

UIView

UIFocusEnvironment

SKNode SCNNode

NEW

Page 59: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Support for SceneKit Making nodes focusable

Opt-in to focus support for SCNNode

node.focusBehavior = .focusable

Also available on SKNode

NEW

Page 60: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•Demo •Focus support in SceneKit

Page 61: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

SceneKit: What's New WWDC 2017

Going Beyond 2D with SpriteKit Executive Ballroom Friday 10:00AM

Support for SceneKit Summary

Focus movement is two-dimensional, based on screen visibility

Focusable SpriteKit scenes on SceneKit surfaces are allowed

Supports moving focus between UIKit, SpriteKit, and SceneKit

All UIFocusEnvironment APIs available

Page 62: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•New Debugging Tools

Page 63: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•Focus Update Logging

Page 64: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Focus Update Logging

Automatically logs focus updates while an application is running

Outlines preferred focus logic

Not for use in production apps (impacts performance)

NEW

Page 65: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•UIFocusDebugger

Page 66: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Used for diagnosing focus-related issues

Structured as a command line tool built into UIKit

Use from LLDB while app is paused, using po

Not for use in application logic

UIFocusDebugger NEW

Page 67: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

UIFocusDebugger Status

(lldb) po UIFocusDebugger.status()

Provides the currently focused item

NEW

Page 68: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

UIFocusDebugger Simulating focus updates

(lldb) po UIFocusDebugger.simulateFocusUpdateRequest(from: environment)

Simulates focus update requests from a specific environment • i.e. a successful call to environment.setNeedsFocusUpdate()

Outlines preferred focus logic used to determine new focus item

NEW

Page 69: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Diagnoses potential issues affecting item focusability

Works on SKNode and SCNNode in addition to UIView

Replaces _whyIsThisViewNotFocusable

UIFocusDebugger Checking focusability

(lldb) po UIFocusDebugger.checkFocusability(for: item)

NEW

Page 70: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

UIView is hidden Ancestor UIView is hidden

UIView alpha is zero Ancestor UIView alpha is zero

UIView user interaction is disabled Ancestor UIView user interaction is disabled

UIView is not in the a window Ancestor UIView is not in a window

UIView returns false from canBecomeFocused Ancestor UIView returns true from canBecomeFocused

UIControl is disabled SpriteKit node not focusable

UITextView is not selectable SpriteKit node user interaction disabled

UISegmentedControl has no enabled segments SceneKit node not focusable

Focus items occluding other focus items

UIFocusDebugger Checking focusability

(lldb) po UIFocusDebugger.checkFocusability(for: item)

NEW

Page 71: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

UIFocusDebugger Status

(lldb) po UIFocusDebugger.help()

Prints detailed instructions for all debugging commands

NEW

Page 72: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

•Demo •Focus Debugging

Page 73: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Summary

New focus update notifications, isFocused, and contains()

Provide consistent animations by targeting coordinated animations

Provide custom focus sounds for more immersive experiences

Use focus interaction in SceneKit for more consistent user experiences

Use UIFocusDebugger and focus update logging to diagnose focus issues

Page 74: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

More Informationhttps://developer.apple.com/wwdc17/224

Page 75: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly

Related Sessions

Advances in TVMLKit WWDC 2017

What’s New in tvOS WWDC 2017

SceneKit: What's New WWDC 2017

Going Beyond 2D with SpriteKit Executive Ballroom Friday 10:00AM

Page 76: •Focus Interaction in tvOS 11...Sound Identifier Description Custom Sound Identifier (e.g. .myCustomIdentifier) Plays the sound registered with this sound identifier..default Explicitly