我有幾個UIImages,我希望用戶能夠單獨拖動每一個。我希望他們能夠觸摸圖像(必須觸摸圖像而不是其他地方),並將其拖動到屏幕上而不影響其他圖像。此代碼移動在同一時間兩個圖像到同一個地方,無論身在何處,用戶在觸摸屏上:如何移動或拖動多個UIImage?
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
playerCardOne.center = location;
playerCardTwo.center = location;
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self touchesBegan:touches withEvent:event];
}
if語句這樣我試着使用,並且它在完全停止的動作,沒有拖動全部:
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if (touch.view == playerCardOne) {
playerCardOne.center = location;
[self.view bringSubviewToFront:(playerCardOne)];
}
else if ([touch view] ==playerCardTwo) {
playerCardTwo.center = location;
[self.view bringSubviewToFront:(playerCardTwo)];
}
}
任何人都可以幫忙嗎?
這仍然只是把圖像和移動它們的確切位置,無論我在屏幕上點擊。 –
沒關係,修復它,謝謝 –