2

我有两点CLLocationCoordinate2D,比如说我的 A 和mapViewB。我想要一个箭头图像从一个点指向另一个点(A-> B)。我无法找到transform箭头图像的正确角度。

请参阅此图片以供参考示例屏幕截图

提前致谢。

4

1 回答 1

7

这是一个老问题,但也许它仍然可以帮助到这里的人:

CGFloat angle = atan2f(point2.y - point1.y, point2.x - point1.x);
CGAffineTransform rotationTransform = CGAffineTransformIdentity;
rotationTransform = CGAffineTransformMakeRotation(angle);
arrow.transform = rotationTransform;

如果您想UIImageView在点 1 放置一个“箭头”,并让它指向点 2,您只需使用增量来获得反正切,然后基于该角度创建一个变换,并将该变换分配给UIImageView箭头。

于 2013-03-25T04:10:13.213 回答