문제

Basically I would just like to touch the image and have it move with my finger across the screen without using theImage.center = touchPosition I don't want to have the center snap to my finger. I want to move the image from whatever point I touch.

도움이 되었습니까?

해결책

The standard way to handle this, which @richard-j-ross-iii hinted at in a comment, is to save the difference between the view's center and the touch position when the drag starts and then maintain that difference as the drag proceeds. In your touchesBegan:withEvent: method save the offset like:

_dragOffsetFromCenter = CGSizeMake(touchLocationInImageView.x - centerOfImageView.x, touchLocationInImageView.y - centerOfImageView.y);

then in touchesMoved:withEvent: you can maintain that same offset like:

myImageView.center = CGPointMake(touchLocation.x - _dragOffsetFromCenter.x, touchLocation.y - _dragOffsetFromCenter.y);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top