gpt4 book ai didi

ios - 如何使用 AutoLayout 在 iphone x 中处理带有安全区域的键盘?

转载 作者:搜寻专家 更新时间:2023-10-30 23:04:31 26 4
gpt4 key购买 nike

<分区>

在 iphone x 中设置安全区域后。当键盘打开安全区域(键盘上方的白色区域)出现在键盘上方时,如何处理键盘?

enter image description here

键盘上方的白色区域。

处理键盘代码:-

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)*/ }

那么如何在不手动操作的情况下以优化的方式解决这个问题呢?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com