Protocol

UIFocusEnvironment

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

Declaration

protocol UIFocusEnvironment

Overview

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.

Topics

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.

Required.

func updateFocusIfNeeded()

Tells the focus engine to force a focus update immediately.

Required.

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.

Required.

Responding to Focus Updates

func didUpdateFocus(in: UIFocusUpdateContext, with: UIFocusAnimationCoordinator)

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

Required.

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.

Required.

var preferredFocusedView: UIView?

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

Deprecated

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.

Required.

var focusItemContainer: UIFocusItemContainer?

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

Required.

Relationships

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.