0

我对触摸事件还很陌生,但我遇到了问题。我使用上面的代码在屏幕上拖动两个图像。但是,当第二根手指触摸屏幕时,代码会起作用,第一个动作就会停止。因此,问题与多点触控有关。我也是,不知道如何计算第二个触摸坐标。我在视图和两个图像中都启用了多点触控。如果有人可以帮助我用每根手指移动每张图像,我会非常满意。提前致谢!

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if ([touch view] == image) {
    image.center = location;
} else if ([touch view] == image2) {
    image2.center = location;
}}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];}
4

1 回答 1

0

我建议为此使用自定义UIGestureRecognizer。它将为您提供一种很好的封装方式来管理您想要的内容。同时拖动两个图像本质上是一种手势。

于 2012-05-11T12:24:40.193 回答