将Tap事件与ImageView分开

时间:2012-08-30 10:43:34

标签: iphone objective-c cocoa-touch uiview uitapgesturerecognizer

我有一个使用TapGestureRecognizer的View。我正在使用TapGestureRecognizer进行单击和双击事件。到现在为止还挺好。现在我在视图顶部添加了一个ImageView,图像视图框架为imageView.frame=CGRectMake(50,290,205,100);

现在,只要我点击View,我的@selectors就会被调用。我想跳过仅针对ImageView的点击事件。怎么做?

我尝试使用

if(recognizer.state == UIGestureRecognizerStateRecognized)
{
    CGPoint point = [recognizer locationInView:recognizer.view];
}

4 个答案:

答案 0 :(得分:2)

您必须实施此检查

if(!CGRectContainsPoint(image.view.frame, point))
  {
     //Complete your Work
   }

答案 1 :(得分:2)

这样做......我希望这会对你有帮助......

每当您点击屏幕时,此委托方法都会调用..

在这种方法中请检查触摸和gestureRecognizer将提供有关您的攻击的一些数据..... 基于此,你可以继续......

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    NSLog(@"%@",touch.description);
    NSLog(@"%@",gestureRecognizer.description);
}

答案 2 :(得分:1)

您需要检查触摸点,

if(!CGRectContainsPoint(image.view.frame, point))
   {
      //Do you work here
    }

答案 3 :(得分:1)

这样做:

if(recognizer.state == UIGestureRecognizerStateRecognized)
{
    CGPoint point = [recognizer locationInView:recognizer.view];
    if(CGRectContainsPoint(imageView.frame,point)
    {
       //igonre
    }
    else
    {
      // continue
    }
}