这拖动多个UIImageViews的是我到目前为止在Array
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
for (UIImageView *imageView in _imageViewArray) {
CGPoint Location = [touch locationInView:touch.view];
imageView.center = Location;
}
}
我面临的问题是,当我移动一个图像都跳了同一个地方。
由于这种cyberpawn这就是我所做的是得到它的工作
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint oldPoint = [touch previousLocationInView:touch.view];
CGPoint newPoint = [touch locationInView:touch.view];
CGPoint diff = CGPointMake(newPoint.x - oldPoint.x, newPoint.y - oldPoint.y);
for (UIImageView *imageView in _imageViewArray) {
if (CGRectContainsPoint(imageView.frame, newPoint)) {
CGPoint cntr = [imageView center];
[imageView setCenter:CGPointMake(cntr.x + diff.x, cntr.y + diff.y)];
}
}
}
这真的很好,唯一的情况是我希望图像能够单独移动,现在它们都一起移动。非常感谢。 – Jonathan
@Jonathan分别移动他们看到我编辑的答案,希望有所帮助! –
@Jonathan再次编辑了一些故障!尝试如果解决了你的问题! –