使用自定义键盘时,keyboardWillShow
运行两次(正常行为),第一个高度为0,但第二个在我的情况下为正确的高度667。问题是,这仅在第二次显示viewController时才是正确的。我第一次得到下面的奇怪输出。
第一次打开视图控制器时进行控制台:
keyboardSize CGRect(来源=(x = 0,y = 258),大小=(宽度= 0,高度= 2.8876618518302306E-314))
第二次打开视图控制器时进行控制台:
keyboardSize CGRect(来源=(x = 0,y = 0),大小=(宽度= 0,高度= 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)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
改变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)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
继续编码.............. :)
归档时间: |
|
查看次数: |
973 次 |
最近记录: |