更改位置inview 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;
i'm using this code below to drag an image across the screen. The one thing i like to change is the location of the image. Right now, the location changes to every touch so everytime i try to move it, it translate to my finger. How do i make it so it can move relative to my finger? e.g. if the image is in the middle of the screen, and i put my finger at the bottom right of the screen, the image don't get translate to my finger. Hope that makes sense. Thanks in advance.
// 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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
uiimage-detecting-touch-and-dragging
这可能会有所帮助..!!
uiimage-detecting-touch-and-dragging
this may help..!!