如何取消一系列UITouch事件? [英] How to cancel a sequence of UITouch events?
问题描述
我有一个 UIImage
视图,可以响应触摸事件。我想取消触摸序列,即,如果触摸超出某些范围,则进一步调用 touchesMoved:
。我怎么能这样做?
I have a UIImage
view that responds to touch events. I want to cancel the touch sequence, i.e., further calls to touchesMoved:
, if the touch goes outside of certain bounds. How can I do that?
我知道在 touchesMoved:
我可以检查触摸物体的坐标和忽略它,但我不知道的是如何完全取消序列。我没有看到中记录的任何方法Apple开发人员 UIResponder
参考我可以致电取消触摸序列。
I know that in touchesMoved:
I can inspect the coordinates of the touch object and ignore it, but what I don't know is how to cancel the sequence altogether. I don't see any method documented in the Apple Developer UIResponder
Reference that I can call to cancel a touch sequence.
推荐答案
这个解决方案可能有点麻烦,但你可以实现并手动调用
This solution may be a bit kludgy, but you could implement and manually call
- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
我基于这个解决方案松散地对我在Apple的 iPhone示例代码网站,我修改了 touchesMoved
方法如下所示:
I am basing this solution loosely on some tweaking I did to the MoveMe sample app on Apple's iPhone sample code site where I modified the touchesMoved
method to look like this:
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
if ([touch view] == placardView)
CGPoint location = [touch locationInView:self];
placardView.center = location;
// I added the following line:
[self touchesCancelled:touches withEvent:event];
return;
}
这篇关于如何取消一系列UITouch事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!