Contents

keyboardWillShowNotification

A notification that posts immediately prior to displaying the keyboard.

Declaration

nonisolated class let keyboardWillShowNotification: NSNotification.Name

Discussion

In iOS 16.1 and later, the notification object is the UIScreen that the keyboard appears on. In earlier versions of iOS, the notification object is nil.

The userInfo dictionary contains information about the keyboard. To get the location and size of the keyboard from the userInfo dictionary, use keyboardFrameBeginUserInfoKey and keyboardFrameEndUserInfoKey.

The keyboard’s frame uses the screen’s coordinate space, which is different than the coordinate space of your views. Although they might sometimes match, such as when your app is full screen, they might be different when your app isn’t full screen, such as in Split View, Slide Over, and Stage Manager. This means you need to account for this difference by converting the keyboard’s frame from the screen’s coordinate space to that of your views. For an example of how to handle this conversion, see keyboardFrameEndUserInfoKey.

The system posts this notification on the main actor. An app running in visionOS never receives this notification. The system displays the keyboard in a separate window, leaving the app’s window unaffected by the keyboard’s appearance and disappearance.

See Also

Constants