Looking for some direction on this. Say you have a ring of radius r. Inside the ring you have a circle of radius c, where c < r. I want the user to be able to grab the inner circle and move/throw it, but circle should be constrained to stay inside the ring. Any suggestions on the following?

  1. handling the touch events
  2. the math involved to constrain the view to a circle?

I am working in iOS, but the concept is general.

有帮助吗?

解决方案

Not sure what you mean by "handling touch events", but here's the math:

hypot(circle.center.y - ring.center.y, circle.center.x - ring.center.x) < (r - c)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top