在touchesMoved方法中检测[UITouch view]
我希望在应用程序中从一个子视图拖动到另一个子视图(并用一条线连接它们),因此我需要跟踪用户触摸的当前视图。
我认为我可以通过简单地在 TouchMoved 方法中调用 [UITouch view] 来实现此目的,但快速查看文档后我发现 [UITouch view] 只返回发生初始触摸的视图。
有谁知道我如何在拖动过程中检测到被触摸的视图?
I wish to drag from one subview to another within my application (and connect them with a line), and so I need to keep track of the current view being touched by the user.
I thought that I could achieve this by simply calling [UITouch view] in the touchesMoved method, but after a quick look at the docs I've found out that [UITouch view] only returns the view in which the initial touch occurred.
Does anyone know how I can detect the view being touched while the drag is in progress?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
还有我的方式:
And my way:
经过更多研究后,我找到了答案。
最初,我是这样检查视图的:
但是,正如我的问题中所解释的,[触摸视图]返回原始触摸发生的视图。这可以通过将上面的代码替换为以下代码来解决:
希望这有帮助
After a bit more research I found the answer.
Originally, I was checking for the view like so:
But, as explained in my question, the [touch view] returns the view in which the original touch occurred. This can be solved by replacing the code above with the following:
Hope this helps
UIView 是 UIResponder 的子类。因此,您可以重写继承自 UIView 的自定义类中的触摸结束/开始方法。您应该向该类添加委托并为其定义协议。在方法
或任何交互中,您只需向对象的委托发送适当的消息并传递该对象即可。例如
UIView is subclass of UIResponder. So you can override touches ended/ began methods in your custom class, that inherits from UIView. Than you should add delegate to that class and define protocol for it. In the methods
or whatever interactions you need just send appropriate message to object's delegate also passing this object. E.g.