UITraitChangeObservable
A type that calls your code in reaction to changes in the trait environment.
Declaration
@MainActor protocol UITraitChangeObservableMentioned in
Overview
Types that conform to UITraitChangeObservable can execute your code in response to changes in their trait collection. When you register for trait changes, the system observes the specified traits, and calls your code when any of the observed traits change value.
Keep your trait registrations focused, and avoid doing work not directly relevant to updated traits. Traits may change more than once before the system updates a view, so avoid expensive work in response to trait changes. For example, use the trait change notification to call setNeedsDisplay(), and update your view in draw(_:).
UIKit cleans up registrations at the end of the object lifecycle. Unregister only in the rare situations when you need to dynamically change which traits you observe.
Topics
Observing trait changes
registerForTraitChanges(_:action:)registerForTraitChanges(_:handler:)registerForTraitChanges(_:target:action:)unregisterForTraitChanges(_:)UITraitChangeObservable.TraitChangeHandlerUITraitChangeRegistration
Registering traits for observation
UITraitAccessibilityContrastUITraitActiveAppearanceUITraitDisplayGamutUITraitDisplayScaleUITraitForceTouchCapabilityUITraitHDRHeadroomUsageLimitUITraitHorizontalSizeClassUITraitImageDynamicRangeUITraitLayoutDirectionUITraitLegibilityWeightUITraitListEnvironmentUITraitPreferredContentSizeCategoryUITraitResolvesNaturalAlignmentWithBaseWritingDirectionUITraitSceneCaptureStateUITraitSplitViewControllerLayoutEnvironmentUITraitTabAccessoryEnvironmentUITraitToolbarItemPresentationSizeUITraitTypesettingLanguageUITraitUserInterfaceIdiomUITraitUserInterfaceLevelUITraitUserInterfaceStyleUITraitVerticalSizeClass