我有 6 个 uiimageviews,比如 img1 - img6。当我触摸并拖动 img1 时,它会移动。但是当我拖动 img1 并且当它靠近其他 uiimageviews 时,img1 停止移动,靠近它的 img 开始移动。当我非常快速地拖动图像而不是当我缓慢拖动图像时会发生这种情况。而且拖动也不是那么顺利...... :(
这是我到目前为止所做的......
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
if (CGRectContainsPoint([self.firstImg frame], [touch locationInView:nil]))
{
[self.view bringSubviewToFront:self.firstImg];
self.firstImg.center = [touch locationInView:nil];
}
else if (CGRectContainsPoint([self.secondImg frame], [touch locationInView:nil]))
{
[self.view bringSubviewToFront:self.secondImg];
self.secondImg.center = [touch locationInView:nil];
}
else if (CGRectContainsPoint([self.thirdImg frame], [touch locationInView:nil]))
{
[self.view bringSubviewToFront:self.thirdImg];
self.thirdImg.center = [touch locationInView:nil];
}
else if (CGRectContainsPoint([self.fourthImg frame], [touch locationInView:nil]))
{
[self.view bringSubviewToFront:self.fourthImg];
self.fourthImg.center = [touch locationInView:nil];
}
else if (CGRectContainsPoint([self.fifthImg frame], [touch locationInView:nil]))
{
[self.view bringSubviewToFront:self.fifthImg];
self.fifthImg.center = [touch locationInView:nil];
}
else if (CGRectContainsPoint([self.sixthImg frame], [touch locationInView:nil]))
{
[self.view bringSubviewToFront:self.sixthImg];
self.sixthImg.center = [touch locationInView:nil];
}
}