UIViewControllerAppearanceEvent
UIViewControllerAppearanceEvent represents a view controller about to appear, having appeared, about to disappear, or having disappeared.
The four appearance events of UIViewController are this class, and animated tells whether this transition is animated.
Inheritance: Event → UIViewControllerAppearanceEvent
Constructor
UIViewControllerAppearanceEvent()
Creates a UIViewControllerAppearanceEvent. The runtime creates one itself when it fires the events below; app code can use it to build an event object and fire it with dispatchEvent() to try out a listener.
Instance properties
Also inherits the properties of Event; the most commonly used are type and target. The properties below are read-only; assigning to them throws TypeError.
| Property | Description |
|---|---|
animated read-only | Whether this appearance or disappearance is animated |
These properties live on the prototype, not on the event object itself: Object.keys(event) and { ...event } don't include them, so read them one by one. See Events with fields.
Events that use this class
| Object | Events |
|---|---|
UIViewController and its subclasses | beforeappear, appear, beforedisappear, disappear |
It can't be canceled: cancelable is false, and preventDefault() has no effect.
Examples
const page = new UIViewController();
page.addEventListener('appear', (e) => {
console.log(e instanceof UIViewControllerAppearanceEvent, e.animated);
});Effect: each time the page has appeared, prints true and whether it was animated.
Corresponding iOS API
| ObjC | JS |
|---|---|
viewWillAppear: | beforeappear |
viewDidAppear: | appear |
viewWillDisappear: | beforedisappear |
viewDidDisappear: | disappear |
The animated parameter | event.animated |
See also
UIViewController: the object that fires these events