更改位置视图UITouch

时间:2011-07-06 10:02:23

标签: ios xcode uitouch

我正在使用下面的代码在屏幕上拖动图像。我想改变的一件事是图像的位置。现在,位置会改变每次触摸,所以每当我尝试移动它时,它会转换为我的手指。我如何制作它可以相对于我的手指移动?例如如果图像位于屏幕中间,并且我将手指放在屏幕的右下角,则图像不会转换为我的手指。希望有道理。提前谢谢。

// get touch event
UITouch *touch = [[event allTouches] anyObject];

// get the touch location
CGPoint touchLocation = [touch locationInView:touch.view];

// move the image view
image.center = touchLocation;

1 个答案:

答案 0 :(得分:0)

uiimage-detecting-touch-and-dragging

这可能会有所帮助.. !!