限制拖动沿着 iPhone 中的路径移动

发布于 2024-08-12 18:38:49 字数 100 浏览 6 评论 0原文

我正在制作一个应用程序,其中球在轨道上滚动。
因此,当我们在屏幕上触摸并拖动球时,它们应该沿着轨道移动。如果阻力距离轨道太远,它应该停止。轨道可以是任何形状。 最好的方法是什么?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热情消退 2024-08-19 18:38:49

这取决于轨迹是如何以编程方式定义的,但是如果您有一个代表它的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文