Ryan Cocuzzo
Ryan Cocuzzo

Reputation: 3219

"Send Message" not visible when keyboard comes up

I am trying to implement a very basic chat feature into my app and I am using constraints to keep everything in the correct place. It is great except for when I need to actually type, and the problem that arises is that the keyboard covers the text field and I not only cannot see the textfield but I cannot dismiss it. Thank you for all help!

In summary,

Upvotes: 0

Views: 59

Answers (2)

Mukul_3062
Mukul_3062

Reputation: 86

Dismiss keyboard by tapping anywhere

override func viewDidLoad() 
{
    super.viewDidLoad() 
    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
    view.addGestureRecognizer(tap)}

func dismissKeyboard() 
{
    view.endEditing(true)
}

Upvotes: 1

7vikram7
7vikram7

Reputation: 2824

Just set observers for UIKeyboardWillShowNotification and UIKeyboardWillHideNotification.

Whenever, UIKeyboardWillShowNotification is triggered, move the UITextfield upwards equivalent to the keyboard height. Then, when the UIKeyboardWillHideNotification is triggered, move the keyboard back into place.

Upvotes: 1

Related Questions