如何取消一系列UITouch事件?

sub*_*e-c 20 iphone uitouch touchesmoved uiresponder ios

我有一个UIImage视图响应触摸事件.touchesMoved:如果触摸超出某些范围,我想取消触摸序列,即进一步调用.我怎样才能做到这一点?

我知道在touchesMoved:我可以检查触摸物体的坐标并忽略它,但我不知道的是如何完全取消序列.我没有看到Apple Developer UIResponderReference中记录的任何方法,我可以调用它来取消触摸序列.

Mic*_*Fey 6

这个解决方案可能有点麻烦,但您可以实现并手动调用

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
Run Code Online (Sandbox Code Playgroud)

我将这个解决方案松散地放在我对Apple的iPhone示例代码网站上的MoveMe示例应用程序进行的一些调整上,其中我将touchesMoved方法修改为如下所示:

- (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;
}
Run Code Online (Sandbox Code Playgroud)