我試圖拖動圖像,並在釋放它之後讓它返回原始位置。 (如在回答看到了這個問題::Basic Drag and Drop in iOS)到目前爲止,我可以使用下面的代碼創建它作爲一個按鈕,拖動圖像拖放對象並將它們返回到原始位置
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self action:@selector(imageTouch:withEvent:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(imageMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[button setImage:[UIImage imageNamed:@"vehicle.png"] forState:UIControlStateNormal];
[self.view addSubview:button];
後來我定義:
- (IBAction) imageMoved:(id) sender withEvent:(UIEvent *) event
{
CGPoint point = [[[event allTouches] anyObject] locationInView:self.view];
UIControl *control = sender;
control.center = point;
}
我怎麼才能讓它在釋放它之後回到它原來的位置呢?對於初學者,我將保存每個圖像應該返回的位置,但是,無論如何,指示UIImage從它的當前位置移動並移動到另一個?或者其他的替代解決方案?
謝謝。但那會立即將UIButton移動到一個新的位置,對嗎?如果是這樣,一旦UIControlEventTouchUpInside上的選擇器被調用,可以命令UIButton從它的當前位置移動到新的位置? – 2011-04-11 22:23:12
閱讀「動畫」 – 2011-04-12 03:13:28