Created
April 15, 2014 21:23
-
-
Save sam33r/10776947 to your computer and use it in GitHub Desktop.
iOS wiring to end editing when the user touches anywhere other than the keypad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Useful for when the keypad is open. | |
// In the view controller: | |
- (void)viewWillAppear:(BOOL)animated | |
{ | |
[super viewWillAppear:animated]; | |
// Listen for taps to end editing | |
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)]; | |
[self.view addGestureRecognizer:gestureRecognizer]; | |
} | |
- (void)tap:(UIGestureRecognizer *)ui | |
{ | |
[self.view endEditing:YES]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment