gpt4 book ai didi

ios - 我似乎无法让我的 KeyboardWillShow 工作?

转载 作者:行者123 更新时间:2023-11-29 06:00:08 26 4
gpt4 key购买 nike

我的代码没有显示任何错误,但是当我启动模拟器时,应用程序崩溃了。我似乎找不到问题,但当我实现“keyboardWillShow”时它开始崩溃。

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

NotificationCenter.default.addObserver(
self,
selector: #selector(keyboardWillShow(with:)),
name: UIResponder.keyboardWillShowNotification,
object: nil)

}

// Mark: Actions

@objc func keyboardWillShow(with notification: Notification) {
let key = "UIKeyboardFrameEndUserInfoKey"
guard let keyboardFrame = notification.userInfo?[key] as? NSValue else { return }
let keyboardHeight = keyboardFrame.cgRectValue.height

buttomConstraint.constant = keyboardHeight

UIView.animate(withDuration: 0.2) {
self.view.layoutIfNeeded()
}
}

最佳答案

Swift 4.2 中有一些变化。我不确定,但请在“keyboardWillShow”中尝试以下操作 - func:

let frameEndUserInfoKey = UIKeyboardFrameEndUserInfoKey
if let kbFrame = notification.userInfo?[frameEndUserInfoKey] as? CGRect {
let keyboardHeight = kbFrame.size.height
buttomConstraint.constant = keyboardHeight

UIView.animate(withDuration: 0.2) {
self.view.layoutIfNeeded()
}
}

关于ios - 我似乎无法让我的 KeyboardWillShow 工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54762711/

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