View1にジェスチャーを設定しているけど、View1の子ビューのView2の中ではジェスチャーを無効にしたいということがある。そういう場合は-gestureRecognizer:shouldReceiveTouch:を使うとよい。
- (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 }
参考:http://stackoverflow.com/questions/3344341/uibutton-inside-a-view-that-has-a-uitapgesturerecognizer