I have a couple of UITextField and UIButton inside a UIScrollView and this scroll view is inside a view of my UIViewController. I added a touch gesture recognizer to dismiss the keyboard if shown:
UITapGestureRecognizer *tapToDismissKeyboard = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
[tapToDismissKeyboard setCancelsTouchesInView:NO];
tapToDismissKeyboard.delegate = self;
[self.view addGestureRecognizer:tapToDismissKeyboard];
#pragma mark UITapGestureRecognizerDelegate
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if ([touch.view isDescendantOfView:self.signupButton_] || [touch.view isDescendantOfView:self.profilePictureImageView_] || [touch.view isDescendantOfView:self.signupUsingFacebook_]) {
return NO; // ignore the touch
}
return YES; // handle the touch
}
The issue is that when I tap the signin/signup button it still detects the tap gesture, in which I actually want the button touch.
you are add your add Gesture Recognizer in whole view if you your button inside that view than it will not take button touch for that create insert all your content inside that view then add Gesture Recognizer for that view only and create another view for your button it will work.