限制拖动沿着 iPhone 中的路径移动
我正在制作一个应用程序,其中球在轨道上滚动。
因此,当我们在屏幕上触摸并拖动球时,它们应该沿着轨道移动。如果阻力距离轨道太远,它应该停止。轨道可以是任何形状。 最好的方法是什么?
I am making an app in which balls roll on tracks.
So when we touch and drag the balls around the screen, they should move along the tracks. If the drag goes out too distant from the track, it should stop. The tracks can be any shape.
What is the best appraoch..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于轨迹是如何以编程方式定义的,但是如果您有一个代表它的 CGPath,或者可以制作一个,则可以在 TouchMoved 方法中使用 CGPathContainsPoint,并且如果球位于路径之外,则拒绝更新球的位置。
It depends on how the track is defined programatically, but it you've got a CGPath that represents it, or can make one, use can use CGPathContainsPoint in the touchesMoved method and refuse to update the position of the ball if it is outside the path.