Monday, 30 September 2013

Using a UITapGestureRecognizer to make keyboard hides, it doesn't work when I touch inside a UIButton

Using a UITapGestureRecognizer to make keyboard hides, it doesn't work
when I touch inside a UIButton

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?

No comments:

Post a Comment