简体   繁体   English

iOS如何通过动画使iPhone指南针航向旋转一圈?

[英]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; 我有一个圆CGRectMake(0.0,0.0,100.0,100.0),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. 然后将带有该图像的UIImageView放在您的指南针上,然后绕其中心点旋转图像。

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... 用于计算圆的x,y坐标...

  • You know the radius of the circle = radius. 您知道圆的半径=半径。
  • You know the angle of rotation = theta. 您知道旋转角度= theta。 (angle is always in rads 2Pi rads = one full turn). (角度始终以弧度为单位2Pi rads =一整圈)。

x coord = radius * cos(theta). x坐标=半径* cos(theta)。

y coord = radius * sin(theta). y坐标=半径* sin(θ)。

That should do it. 那应该做。

You may have to convert from RADs into degrees. 您可能需要从RAD转换为学位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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