Alex Rivera | Logout

How can I dismiss the keyboard if a user taps off the on-screen keyboard?

Asked 2011-04-19T03:58:21.483
42

I want to be able to dismiss the iPhone keyboard when the user taps anywhere outside of the keyboard. How can I go about doing this? I know I need to dismiss the responder, but need to know how to implement it when a user taps out of the keyboard space.

Edit
Report

1 Answer

16

Add a tapGesture Recognizer but make sure cancelsTouchesInView = NO

UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(closeTextInput)];
tapGesture.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tapGesture];
[tapGesture release];
answered 2012-06-21T15:55:41.553

Your Answer