IB に 4 つの UIImageView が設定されています。ステータスを説明する UILabel もあります (以下のコードで説明)。touchesBegan、touchesMoved、および touchesEnd メソッドを使用して、次のようにオブジェクトの動きをキャプチャします。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* aTouch = [touches anyObject];
UIView* aView = [aTouch view];
if (aView != self.view) {
[self.view bringSubviewToFront:aView];
self.statusLabel.text = @"You're Dragging...";
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch* aTouch = [touches anyObject];
UIView* aView = [aTouch view];
if (aView != self.view) {
aView.center = [aTouch locationInView:self.view];
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
self.statusLabel.text = @"At Ease";
}
問題は、(シミュレーターで) UIImageViews の 1 つを移動した後、ドロップした場所にとどまるのではなく、IB のセットとして元の位置に「ジャンプ」して戻ることです。
なぜそれが起こるのですか?「touchesEnd」でUIImageViewの新しい位置を「キャプチャ」し、この「ジャンプ」を回避するにはどうすればよいですか?
PS「touchesEnd」でラベルを更新しないと、別のUIImageViewをクリックするまでUIImageViewが最後の位置に留まることに気付きました。ここで何が起こっているのですか?