帮助我理解iPhone的touchesBegan实现和拖动UIView
我知道这个问题之前已经得到了回答(iPhone“touchesBegan”和“touchesMoved”消息......不要移动到触摸中心 ),但我对 iPhone 开发非常陌生,所以不明白答案。
本质上,我想做的是有一个 UIImageView 响应触摸,在屏幕上移动它。来自Apple的示例具有这样的视图:当它有touchesBegan时,将其中心移动到触摸处,然后移动视图。
我想要的是图像像使用 UIImagePicker 时那样平移。所选图像不会随着触摸而对齐,而是会随着触摸而移动。
任何帮助将不胜感激。
I know this has been sort of answered before ( iPhone "touchesBegan" and "touchesMoved" message ... do not move to centre of touch ), but I'm very new to iPhone development so don't understand the answer.
Essentially, what I want to do is have a UIImageView which responds to touches, to move it around the screen. The sample from Apple has the view that when it has touchesBegan, moves its centre to the touch, then moves the view.
What I'd like is for the image to pan like when you use the UIImagePicker. The selected image does not snap to the touch, but instead will move from the touch.
Any help would be most appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要找到第一次触摸屏幕的点。然后,对于每个“触摸移动”,获取新点的增量 x 和 y 坐标,并将图像移动该量。
无论如何。我希望你能明白我想说的。
First you need to get the point where you first touched the screen. Then for each 'touch moved' get the delta x and y coordinates for the new point and move the image by that amount.
something like that anyway. I hope you get the idea of what I am trying to say.