[英]iOS: UIVIew touches delegates vs single tap recognizer
I am handling Touches
delegates and UITapGestureRecognizer
for single tap. 我正在处理
Touches
委托和UITapGestureRecognizer
的单次点击。 Following are the methods. 以下是方法。 When I single tap on my View, I get three events in order of
TouchesBegan
, SingleTap
, and TouchesEnded
. 当我在视图上单击时,
SingleTap
TouchesBegan
, SingleTap
和TouchesEnded
顺序获得三个事件。 Is there anyway to stop TouchesEnded
event when I have SingleTap
detected? 反正是有停止
TouchesEnded
事件我已经当SingleTap
检测? Basicaaly I don't want to perform tasks in TouchesEnded
if TouchesMoved
didn't happen. 基本上,如果
TouchesMoved
没有发生,我不想在TouchesEnded
执行任务。 I have done this using failTouchEnded BOOL variable in SingleTap
and checking it in TouchesEnded but not sure if it is a good idea! 我已经在
SingleTap
使用failTouchEnded BOOL变量并在SingleTap
中SingleTap
进行了检查,但不确定是否是一个好主意!
- (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;
}
gestureRecognizer has a property cancelsTouchesInView. gestureRecognizer的属性为cancelsTouchesInView。 if it is YES (which is default) cancels the touches if the gesture recognizer recognizes the gesture.
如果为YES(默认),则在手势识别器识别到手势时取消触摸。 So you will get a touches canceled instead of touches ended.
因此,您将获得取消的触摸,而不是结束的触摸。 You should set delaysTouchesEnded to YES too if it is not YES
如果不是,也应该将delaysTouchesEnded设置为YES。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.