A set of methods that define the focus behavior for a branch of the view hierarchy.


protocol UIFocusEnvironment


The UIFocusEnvironment protocol provides a common interface for specifying and reacting to focus behavior throughout your app. Classes in UIKit that conform to this protocol include UIView, UIViewController, UIWindow, and UIPresentationController; in other words, classes that are either directly or indirectly in control of views on the screen.


Requesting Focus Update

When to request a focus update.

func setNeedsFocusUpdate()

Submits a request to the focus engine for a focus update in this environment.


func updateFocusIfNeeded()

Tells the focus engine to force a focus update immediately.


Validating Focus Movements

func shouldUpdateFocus(in: UIFocusUpdateContext) -> Bool

Returns a Boolean value indicating whether the focus engine should allow the focus update described by the specified context to occur.


Responding to Focus Updates

func didUpdateFocus(in: UIFocusUpdateContext, with: UIFocusAnimationCoordinator)

Called immediately after the system updates the focus to a new view.


Controlling User-Generated Focus Movements

var preferredFocusEnvironments: [UIFocusEnvironment]

An array of focus environments, ordered by priority, to which this environment prefers focus to be directed during a focus update.


var preferredFocusedView: UIView?

Specifies the view that should be focused if this environment is focused.


Getting the Sound to Play During Updates

Using Custom Sounds for Focus Movement

Customize the sounds users hear when focus moves.

func soundIdentifierForFocusUpdate(in: UIFocusUpdateContext) -> UIFocusSoundIdentifier?

Asks the delegate for the identifier of the sound to play when the object gains focus.

struct UIFocusSoundIdentifier

An identifier for a focus-related sound.

Checking the Ancestry of the Environment

func contains(UIFocusEnvironment) -> Bool

Returns a Boolean value indicating whether the focus environment contains the specified environment.

var parentFocusEnvironment: UIFocusEnvironment?

The parent focus environment for this environment.


var focusItemContainer: UIFocusItemContainer?

The container for the child focus items in this focus environment.



Inherits From

Inherited By

See Also

Focus Interactions

About Focus Interactions for Apple TV

Design and implement intuitive control schemes for menus and interactive user interface layouts.

Adding User-Focusable Elements to a tvOS App

Create intuitive and easily manipulated user-interactive controls for your tvOS app.

class UIFocusSystem

Queries and reevaluates the currently focused item.

class UIFocusUpdateContext

An object that provides information relevant to a specific focus update from one view to another.

protocol UIFocusItem

An object that can become focused.

class UIFocusMovementHint

Provides movement hint information for the focused item.

protocol UIFocusItemContainer

The container responsible for providing geometric context to focus items within a given focus environment.

protocol UIFocusItemScrollableContainer

A type of focus item container that supports automatic scrolling of focusable content.