2

我有一个 UIView 和一个点击手势识别器:

UIImageView *tabView = [[UIImageView alloc] initWithFrame:CGRectMake(41, 145, 702, 100)];
tabView.image = [UIImage imageNamed:@"inactive_tab"];
tabView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
                                        action:@selector(handleSingleTap:)];
[tabView addGestureRecognizer:singleFingerTap];
[self.scrollView addSubview:tabView];

我在滚动视图上添加了另一个视图:

[self.scrollView addSubview:self.activeTab];

activeTab 在 inactiveTap 之上。当我点击 activeTap 时,手势识别器会触发,我不想发生这种情况。我怎样才能避免这种情况?

4

1 回答 1

9

用途UIGestureRecognizerDelegate及其方法gestureRecognizer:shouldReceiveTouch:。您可以检查触摸点是否在视图框架内,NO如果您不希望触摸发生在该视图上,则返回。`

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    CGPoint touchLocation = [touch locationInView:self.view];
    return !CGRectContainsPoint(self.activeTab.frame, touchLocation);
}
于 2013-03-06T10:33:18.723 回答