© 2016 Apple Inc. All rights reserved. Redistribution or public display not permitted without written permission from Apple.
App Frameworks #WWDC16
Session 215
Focus Interaction on tvOS
Matthew Ricketson UIKit Frameworks Engineer
Session 215
ReviewPreferred Focus
Window
Root View
Subview SubviewContainer
Root View Controller
prefers
Subview
ReviewPreferred Focus
Window
Root View
Subview SubviewContainer
Root View Controller
prefers
prefers
Subview
ReviewPreferred Focus
Window
Root View
Subview SubviewContainer
Root View Controller
prefers
prefers
SubviewSubview
prefers
New APIPreferred Focus Environments
public protocol UIFocusEnvironment : NSObjectProtocol { public var preferredFocusEnvironments: [UIFocusEnvironment] { get } }
NEW
New APIPreferred Focus Environments
Benefits:
public protocol UIFocusEnvironment : NSObjectProtocol { public var preferredFocusEnvironments: [UIFocusEnvironment] { get } }
NEW
New APIPreferred Focus Environments
Benefits:• Prefer non-item focus environments
public protocol UIFocusEnvironment : NSObjectProtocol { public var preferredFocusEnvironments: [UIFocusEnvironment] { get } }
NEW
New APIPreferred Focus Environments
Benefits:• Prefer non-item focus environments• Prefer multiple ordered focus environments
public protocol UIFocusEnvironment : NSObjectProtocol { public var preferredFocusEnvironments: [UIFocusEnvironment] { get } }
NEW
SubviewSubview
Preferred Focus Environments
Container View Controller
NEW
Child VC #1 Child VC #2
class ContainerViewController: UIViewController {
override var preferredFocusEnvironments: [UIFocusEnvironment] { return [childVC1, childVC2] }
}
SubviewSubview
Preferred Focus Environments
Container View Controller
NEW
not focusable
Child VC #1 Child VC #2
class ContainerViewController: UIViewController {
override var preferredFocusEnvironments: [UIFocusEnvironment] { return [childVC1, childVC2] }
}
SubviewSubview
Preferred Focus Environments
Container View Controller
NEW
focusable
Child VC #1 Child VC #2
Subviewnot focusable
class ContainerViewController: UIViewController {
override var preferredFocusEnvironments: [UIFocusEnvironment] { return [childVC1, childVC2] }
}
Restoring Focus
Root View Controller
Presented
Detail View Controller
Cell
Cell Cell
Cell
Button
Button
Default ButtonDefault Button
public class UIViewController : … { public var restoresFocusAfterTransition: Bool }
New APIRestoring Focus NEW
public class UIViewController : … { public var restoresFocusAfterTransition: Bool }
True by default
New APIRestoring Focus NEW
public class UIViewController : … { public var restoresFocusAfterTransition: Bool }
True by defaultAffects presentation, push/pop, and tab bar selection
New APIRestoring Focus NEW
DemopreferredFocusEnvironments and restoresFocusAfterTransition
Brandon Kieft tvOS Software Engineer
OverviewFocus Interaction in SpriteKit
Shared Focus API across UIKit and SpriteKitOpt-in for SpriteKit
NEW
OverviewFocus Interaction in SpriteKit
Shared Focus API across UIKit and SpriteKitOpt-in for SpriteKitSeamless focus movement between views and nodes
NEW
Focus Interaction in SpriteKit
UIView
var canBecomeFocused: Bool
UIFocusEnvironment
UIFocusItem
SKNode
NEW
UIFocusUpdateContext APIFocus Interaction in SpriteKit NEW
public class UIFocusUpdateContext : NSObject {
}
weak public var previouslyFocusedItem: UIFocusItem? { get }
weak public var nextFocusedItem: UIFocusItem? { get }
UIScreen APIFocus Interaction in SpriteKit NEW
public class UIScreen : NSObject {
}
weak public var focusedItem: UIFocusItem? { get }
UIFocusEnvironment APIFocus Interaction in SpriteKit
public protocol UIFocusEnvironment : NSObjectProtocol {
}
NEW
UIFocusEnvironment APIFocus Interaction in SpriteKit
public protocol UIFocusEnvironment : NSObjectProtocol {
}
NEW
weak optional public var preferredFocusedView: UIView? { get }
UIFocusEnvironment APIFocus Interaction in SpriteKit
public protocol UIFocusEnvironment : NSObjectProtocol {
}
public var preferredFocusEnvironments: [UIFocusEnvironment] { get }
NEW
weak optional public var preferredFocusedView: UIView? { get }
UIFocusEnvironment APIFocus Interaction in SpriteKit
public protocol UIFocusEnvironment : NSObjectProtocol {
}
public var preferredFocusEnvironments: [UIFocusEnvironment] { get }
NEW
@available(tvOS, introduced: 9.0, deprecated: 10.0) weak optional public var preferredFocusedView: UIView? { get }
SummaryFocus Interaction in SpriteKit
Focus API supports both UIKit and SpriteKitUIView and SKNode conform to UIFocusItem
SummaryFocus Interaction in SpriteKit
Focus API supports both UIKit and SpriteKitUIView and SKNode conform to UIFocusItemOpt-in for SpriteKit
SummaryFocus Interaction in SpriteKit
Focus API supports both UIKit and SpriteKitUIView and SKNode conform to UIFocusItemOpt-in for SpriteKitNo changes required for UIKit-only apps
SummaryFocus Interaction in SpriteKit
Focus API supports both UIKit and SpriteKitUIView and SKNode conform to UIFocusItemOpt-in for SpriteKitNo changes required for UIKit-only apps
What’s New in SpriteKit Presidio Thursday 5:00PM
RecommendationsBuilding a Custom Control
Subclass UIControlUse the focus animation coordinatorUse motion effects
TestingBuilding a Custom Control
Input devices have different capabilitiesTest using different input devices
TestingBuilding a Custom Control
Input devices have different capabilitiesTest using different input devicesTest with accessibility
Summary
Preferred focus enhancementsFocus interaction support for SpriteKitBuilding a custom, focusable control
Focus-Driven Interfaces with UIKit
Covers the basicsIn-depth Focus API overviewBest practicesTools and debugging supporthttps://developer.apple.com/videos/techtalks-apple-tv/
Apple TV Tech Talks 2016
Related Sessions
What’s New in tvOS Presidio Tuesday 3:00PM
Mastering UIKit on tvOS Presidio Wednesday 10:00AM
What’s New in SpriteKit Presidio Thursday 5:00PM
Top Related