LoginSignup
18
17

More than 5 years have passed since last update.

# ある特定の View だけ UIGestureRecognizer のイベントを受け取らない

Posted at

一番奥の UIViewUIGestureRecognizer を設置し、手前に UIButton などを設置した時、UIButton を押しても UIGestureRecognizer のイベントが起きてしまう。

こういう時は Delegate メソッドの - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch; を使う。

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    // test if our control subview is on-screen
    if (self.controlSubview.superview != nil) {
        if ([touch.view isDescendantOfView:self.controlSubview]) {
            // we touched our control surface
            return NO; // ignore the touch
        }
    }
    return YES; // handle the touch
}

via: http://stackoverflow.com/questions/3344341/uibutton-inside-a-view-that-has-a-uitapgesturerecognizer

18
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
17