点击按钮时忽略UIGestureRecognizer

smo*_*ter 8 iphone ipad ios

我有一个手势识别器设置,以便在点击屏幕时我的工具栏向下滑动.当我点击栏上的按钮时,这就算是一个点击.在这些情况下如何取消手势?

谢谢

jam*_*guy 15

您可以查看SimpleGestureRecognizers示例项目.

http://developer.apple.com/library/ios/#samplecode/SimpleGestureRecognizers/Introduction/Intro.html

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

    // Disallow recognition of tap gestures in the button.
    if ((touch.view == button) && (gestureRecognizer == tapRecognizer)) {
        return NO;
    }
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

  • 我的解决方案是`return!([touch.view isKindOfClass [UIButton class]])`以允许我视图中所有按钮的事件. (6认同)
  • 此if语句适用于忽略工具栏中的每个按钮.我花了一分钟才找到它,认为这可能值得补充.if([touch.view isDescendantOfView:_toolbar]) (3认同)