The additional top comes from the container’s secure space, the realm that incorporates the “residence swipe bar” on iPhone 15 and different fashions.
keyboardFrameEndUserInfoKey
consists of the container’s secure space too, however you solely ignored the .keyboard
secure space, and that is why the crimson space seems greater than what you count on.
One workaround is to disregard all secure areas relying on whether or not the keyboard is exhibiting.
// change the present ignoresSafeArea modifier with this:
.ignoresSafeArea(keyboardHeight == 0 ? [] : .all)
Alternatively, you may keep away from utilizing NotificationCenter
, and do that in pure SwiftUI. All you want is to learn the container secure space, and the overall secure space, and subtract one from the opposite.
GeometryReader { whole in // that is the overall secure space, as a result of no secure space is ignored
GeometryReader { container in // that is the container secure space, as a result of we ignored the keyboard secure space
VStack {
TextField("Check", textual content: $textual content)
Shade.crimson
// we subtract it right here:
.body(top: whole.safeAreaInsets.backside - container.safeAreaInsets.backside)
}
.body(maxHeight: .infinity, alignment: .backside)
}
.ignoresSafeArea(.keyboard)
}