Reputation: 652
Pop up UIView hidden when keyboard shown or click on Textfield!
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
}
}
}
Upvotes: 1
Views: 107
Reputation: 601
Your code for setting UIView frame when keyboard show up is wrong.
Replace
self.view.frame.origin.y -= keyboardSize.height
by
self.view.frame.origin.y = UIScreen.mainScreen().bounds.size.height - (keyboardSize.height + self.view.frame.size.height)
Upvotes: 1