能够通过“触摸”移动多个图像

时间:2013-03-11 02:34:30

标签: objective-c

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [[event touchesForView:self.view] anyObject];
    CGPoint point = [touch locationInView:self.view];

    basketView.center = CGPointMake(point.x, point.y);


}

我目前有这个代码可以让用户用手指移动图像。但是,如果我想在屏幕上添加多个可移动图像(比如我也希望能够移动UIImages basketView2和basketView3),我将如何更改代码以允许此操作?

1 个答案:

答案 0 :(得分:1)

您只需要修改以下代码

UITouch *touch = [[event touchesForView:self.view] anyObject];
CGPoint point = [touch locationInView:self.view];
UIImageView *currentView=(UIImageView *)touch.view;
currentView.center = CGPointMake(point.x, point.y);