开发者

Ignoring UIGestureRecognizer when hitting button

开发者 https://www.devze.com 2023-03-04 06:16 出处:网络
I have a gesture recognizer set up so that my toolbar slides down when the screen is 开发者_Go百科tapped.When I hit a button on the bar, that counts as a tap.How do I cancel the gesture in those cases

I have a gesture recognizer set up so that my toolbar slides down when the screen is 开发者_Go百科tapped. When I hit a button on the bar, that counts as a tap. How do I cancel the gesture in those cases?

Thanks


You can look at the SimpleGestureRecognizers sample project.

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;
}


In Swift:

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    if touch.view is UIButton {
        return false
    }
    return true
}
0

精彩评论

暂无评论...
验证码 换一张
取 消