移动一个不使用center属性的UIImageView



基本上我只是想触摸图像,让它移动与我的手指在屏幕上没有使用图像。center = touchPosition我不想让中间的东西夹在我的手指上。我想把图像从我触摸到的任何点移动

处理这个问题的标准方法,@richard-j-ross-iii在评论中暗示,是在拖动开始时保存视图中心和触摸位置之间的差异,然后在拖动进行时保持该差异。在touchesBegan:withEvent:方法中保存偏移量如下:

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

则在touchesMoved:withEvent:中可以保持相同的偏移量,如

myImageView.center = CGPointMake(touchLocation.x - _dragOffsetFromCenter.x, touchLocation.y - _dragOffsetFromCenter.y);

最新更新