在使用自定义键盘,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)
}
}
}
}
更改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)
}
}
}
}
保持编码.............. :)