【问题标题】:Dragging two images using multi touch使用多点触控拖动两个图像
【发布时间】:2012-05-11 12:21:33
【问题描述】:

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

-(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];}

【问题讨论】:

    标签: xcode image drag touches multi-touch


    【解决方案1】:

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

    【讨论】:

    猜你喜欢
    • 2012-10-09
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 2011-03-04
    相关资源
    最近更新 更多