あまりイベントを取得しないUIImageView
ので、次のようなものを使用UIButton
してドラッグしてみてください。
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;
}
中心点が他のメソッドと一致してUIButton を追加するUIView
場合[UIView adSubview:]
UIView
iOSの基本的なドラッグアンドドロップからこのコードを取得しました
見てみましょう : Superview の境界内で画像をドラッグする