iOS:UIVIew触及代表与单击识别器

时间:2013-01-07 15:33:54

标签: ios uiview uitapgesturerecognizer touchesbegan touchesmoved

我正在处理Touches个代表和UITapGestureRecognizer进行单击。以下是方法。当我点击我的视图时,我会按TouchesBeganSingleTapTouchesEnded的顺序获得三个事件。当我检测到TouchesEnded时,是否有停止SingleTap事件? Basicaaly如果TouchesEnded没有发生,我不想在TouchesMoved执行任务。我使用SingleTap中的failTouchEnded BOOL变量并在TouchesEnded中检查它,但不确定它是否是个好主意!

   - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    }

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
          failTouchEnded = NO;
    }

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
          if(failTouchEnded) return;

    }

    - (void)GestureView:(GestureView*)view handleSignleTap:(UITapGestureRecognizer*)recognizer {
          failTouchEnded = YES;
    }

1 个答案:

答案 0 :(得分:0)

gestureRecognizer有一个属性cancelsTouchesInView。如果是(这是默认的),如果手势识别器识别出手势,则取消触摸。所以你会取消触摸而不是触摸结束。如果不是,则应将delayedTouchesEnded设置为YES