Arun sharma
Arun sharma

Reputation: 652

UIView Hides on Keyboard Appear

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

Answers (1)

Pankaj Yadav
Pankaj Yadav

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

Related Questions