gpt4 book ai didi

ios - 如何将 "move view with keyboard"函数实现到文本字段中

转载 作者:行者123 更新时间:2023-11-28 13:55:17 25 4
gpt4 key购买 nike

我想将该功能实现到我的文本字段的功能中。我尝试了不同的方法,但我无法成功。
这是代码:

NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue {
if self.view.frame.origin.y == 0 {
self.view.frame.origin.y -= keyboardSize.height
}
}
}

最佳答案

您使用的键 UIResponder.keyboardFrameBeginUserInfoKey 导致您得到错误的高度。

改用这个键:

UIResponder.keyboardFrameEndUserInfoKey

关于ios - 如何将 "move view with keyboard"函数实现到文本字段中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53967740/

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