I have declared in my header file this:
UITapGestureRecognizer* tap;
And on viewDidLoad
:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(hideKeyboard)];
tap.enabled = NO;
[self.view addGestureRecognizer:tap];
}
I've added UITextFieldDelegate
, and added this:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
tap.enabled = YES;
return YES;
}
If I touches anywhere outside the keyboard, it disappears, but if I touch in a UIButton
it doesn't disappear.
Do you know why?