Reputation: 3219
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
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
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