简体   繁体   中英

iOS how to make iPhone compass heading move around a circle with animation?

I have a circle CGRectMake(0.0, 0.0, 100.0, 100.0) with cornerRadius = 100;

I want to move an image around that circle. The image should move around the circle and point to the north. In other words it's a compass, just the heading doesn't rotate, but moves around the circle. Also I need the animation to move forwards and backwards just like on a compass.

Has anyone implemented something like this or have any suggestions or ideas?

Instead of trying to work out the coors of it I'd just have an image that is the same size as the entire compass but completely transparent apart from the pointer which will sit on the top edge.

Then put a UIImageView with this image over your compass and just rotate the image around its centre point.

That way the pointer will always follow a circle and it's easier to point north because you're just dealing with an angle of rotation instead of coordinates.

For calculating the x,y coords for the circle...

  • You know the radius of the circle = radius.
  • You know the angle of rotation = theta. (angle is always in rads 2Pi rads = one full turn).

x coord = radius * cos(theta).

y coord = radius * sin(theta).

That should do it.

You may have to convert from RADs into degrees.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM