在 iphone x 中设置安全区域后。当键盘打开安全区(键盘上方的白色区域)出现在键盘上方时,如何处理键盘?
键盘上方的白色区域。
手柄键盘代码:-
func keyboardWillChangeFrameWithNotification(_ notification: Notification, showsKeyboard: Bool) {
let userInfo = notification.userInfo!
let animationDuration: TimeInterval = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as! NSNumber).doubleValue
let keyboardScreenEndFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as! NSValue).cgRectValue
// keyboardRect = [self.view convertRect:keyboardRect fromView:nil];
let keyBoardRect = self.view.convert(keyboardScreenEndFrame, from:nil)
UIView.animate(withDuration: animationDuration, delay: 0, options: .beginFromCurrentState, animations: {
// Keyboard is going to appear. move composebar up
if showsKeyboard {
self.constraintBottomAttachmentView.constant = keyBoardRect.size.height
} else { // Keyboard is going to disappear. Move composebar down.
self.constraintBottomAttachmentView.constant = 0
}
self.view.layoutIfNeeded()
}, completion: { finished in
// Update the height of recipient bar.
self.updateRecipientBarMaxHeight()
})
}
iphone x 中的键盘高度增加了,所以如果我从键盘高度减去 - 34,白色区域会减小。代码:-
if showsKeyboard {
self.constraintBottomAttachmentView.constant = keyBoardRect.size.height - self.view.safeAreaInsets.bottom /*(34)*/ }
那么如何在不手动执行此操作并以优化方式解决此问题?