gpt4 book ai didi

ios - 增加框架的大小 - Keyboardwillshow - Swift

转载 作者:搜寻专家 更新时间:2023-11-01 07:06:04 25 4
gpt4 key购买 nike

我的代码在第一次调用键盘时似乎运行良好。第二次调用键盘时,帧大小没有增加。

这是我的代码:

@objc func keyboardWillShow(sender: NSNotification) {

let _: [NSObject : AnyObject] = sender.userInfo! as [NSObject : AnyObject]

let keyboardSize: CGSize = (sender.userInfo?[UIKeyboardFrameBeginUserInfoKey]! as AnyObject).cgRectValue.size
let offset: CGSize = (sender.userInfo?[UIKeyboardFrameEndUserInfoKey]! as AnyObject).cgRectValue.size

if keyboardSize.height == offset.height {
UIView.animate(withDuration: 0.25, delay: 0.0, options: [.allowUserInteraction], animations: {
let frame = self.view.frame
self.view.frame = CGRect(x: 0, y: self.fullView, width: frame.width, height: frame.height)
})

noteDetails.frame.size.height = noteDetails.frame.size.height + keyboardSize.height
} else {
UIView.animate(withDuration: 0.25, delay: 0.0, options: [.allowUserInteraction], animations: {
let frame = self.view.frame
self.view.frame = CGRect(x: 0, y: self.fullView, width: frame.width, height: frame.height)
})

noteDetails.frame.size.height = noteDetails.frame.size.height + keyboardSize.height - offset.height
}
}

@objc func keyboardWillHide(sender: NSNotification) {
let _: [NSObject : AnyObject] = sender.userInfo! as [NSObject : AnyObject]

let keyboardSize: CGSize = (sender.userInfo?[UIKeyboardFrameBeginUserInfoKey]! as AnyObject).cgRectValue.size

noteDetails.frame.size.height = noteDetails.frame.size.height + keyboardSize.height

}

我添加了偏移量以检查自定义键盘高度并根据它增加高度。我觉得这会导致代码崩溃。具体来说,到我第二次调用键盘时,keyboardSize 的高度应该是自定义键盘的高度。不确定如何修复我的代码,使表格框架的高度随着键盘的高度而增加,对于自定义键盘和常规键盘都是如此。

最佳答案

使用 UIKeyboardFrameEndUserInfoKey 而不是 UIKeyboardFrameBeginUserInfoKey

关于ios - 增加框架的大小 - Keyboardwillshow - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47965343/

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