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


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. Third-party classes should not conform to the UIFocusEnvironment protocol.


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)

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.


Checking the Ancestory of the Environment

func contains(UIFocusEnvironment)

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


Getting the Sound to Play During Updates

func soundIdentifierForFocusUpdate(in: UIFocusUpdateContext)

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.



Inherits From

Inherited By

See Also

Focus Interactions

class UIFocusGuide

An object that exposes nonview areas as focusable.

protocol UIFocusItem

A protocol—not intended for conformance by third-party classes—that lets an item declare its ability to participate in the focus system.

class UIFocusSystem

The current state of the user interface's focus system.

class UIFocusUpdateContext

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

class UIFocusAnimationCoordinator

A coordinator of focus-related animations during a focus update.

class UIFocusDebugger

A runtime object for debugging focus-related interactions.


Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software