我6周的UIImageViews,說IMG1 - img6。當我觸摸並拖動img1時,它會移動。但我拖動IMG1,當它來到附近其他的UIImageViews的IMG1停止移動並且來到附近它的IMG,開始移動。發生這種情況時,我很快拖動圖像,而不是當我拖動圖像緩慢。同時,也是拖動也不是那麼順利...... :(禁用其他的UIImageViews當一個的UIImageView被觸摸
這裏是我到目前爲止已經完成了...
- (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];
}
}
嘗試設置其他圖像視圖的'userInteractionEnabled:NO'當你拖動imageView1。 – Zen
我試過....但沒有運氣...... :( – AKB
順便說一句,如果我得到它的權利,你正試圖實施平移,你應該使用'UIPanGestureRecognizer',如果是這樣的話 – Zen