当键盘显示或点击Textfield时弹出隐藏的UIView !
My Code for KeyBoard show:
func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue() {
if self.view.frame.origin.y == 0 {
self.view.frame.origin.y -= keyboardSize.height
}
}
}
func keyboardWillHide(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue() {
if self.view.frame.origin.y != 0 {
self.view.frame.origin.y += keyboardSize.height
}
}
}
当键盘显示时设置UIView框架的代码是错误的。
代替self.view.frame.origin.y -= keyboardSize.height
self.view.frame.origin.y = UIScreen.mainScreen().bounds.size.height - (keyboardSize.height + self.view.frame.size.height)