我在 UIScrollView 中有几个 UITextField 和 UIButton,这个滚动视图在我的 UIViewController 的视图中。如果显示,我添加了一个触摸手势识别器来关闭键盘:
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
}
问题是当我点击登录/注册按钮时,它仍然会检测到点击手势,我实际上想要按钮触摸。