Notes WWDC 2021 : Your guide to keyboard layout
Mes notes pour la session Your guide to keyboard layout de la WWDC 2021.
Layout guide
Notification-based keyboard layout remains available.
New: UIKeyboardLayoutGuide
- Basic use case: update to use
.topAnchor
- Matches animations
- Follows height changes
- Bottom of safe area when undocked
view.keyboardLayoutGuide.topAnchor.constraint(equalToSystemSpacingBelow: textView.bottomAnchor, multiplier: 1.0).isActive = true
Integrating the keyboard
Not just a layout guide:
.followsUndockedKeyboard
(false
by default)- Subclass of
UITrackingLayoutGuide
, can specify constraintsnear
/away
specific edge
let awayFromTopConstraints = [
view.keyboardLayoutGuide.topAnchor.constraint(equalTo: editView.bottomAnchor),
]
view.keyboardLayoutGuide.setConstraints(awayFromTopConstraints, activeWhenAwayFrom: .top)
let nearTopConstraints = [
view.safeAreaLayoutGuide.bottomAnchor.constraint(equalTo: editView.bottomAnchor)
]
view.keyboardLayoutGuide.setConstraints(nearTopConstraints, activeWhenNearEdge: .top)
Types of keyboards
- Text input via camera: same as docked keyboard, but can be fullscreen
- Shortcuts bar: width is adaptive, can be collapsed