gpt4 book ai didi

ios - keyboardWillShow 第一次显示奇怪的高度

转载 作者:可可西里 更新时间:2023-11-01 00:37:26 25 4
gpt4 key购买 nike

当使用自定义键盘时,keyboardWillShow 运行两次(正常行为),第一次高度为 0,但第二次是正确的高度,在我的例子中是 667。问题是这只是真实的第二次显示 viewController。我第一次得到下面的奇怪输出。

第一次打开 View Controller 时的控制台:

keyboardSize CGRect (origin = (x = 0, y = 258), size = (width = 0, height = 2.8876618518302306E-314))

控制台第二次打开 View Controller :

keyboardSize CGRect (origin = (x = 0, y = 0), size = (width = 0, height = 667))

我的代码:

NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil)

func keyboardWillShow(notification: NSNotification) {
if let userInfo = notification.userInfo {
if let keyboardSize = (userInfo[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
if keyboardSize.height > 0 { //in case of custom keyborad
kbHeight = keyboardSize.height
self.animateTextField(true)
}
}
}
}

最佳答案

UIKeyboardFrameBeginUserInfoKey 更改为 UIKeyboardFrameEndUserInfoKey。就这些:

func keyboardWillShow(notification: NSNotification) {
if let userInfo = notification.userInfo {
if let keyboardSize = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() {
if keyboardSize.height > 0 { //in case of custom keyborad
kbHeight = keyboardSize.height
self.animateTextField(true)
}
}
}
}

继续编码.......... :)

关于ios - keyboardWillShow 第一次显示奇怪的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31923919/

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