【问题标题】:Rotating only the MapView's content仅旋转 MapView 的内容
【发布时间】:2010-02-28 20:22:17
【问题描述】:

我正在尝试根据用户当前的路线在我的应用中旋转地图视图。 (我不喜欢使用内置指南针,因为只有 3GS 使用它,并且受到其他机器(即您自己的汽车)的干扰太大。)。

CGAffineTransformMakeRotation 方法将旋转整个地图视图,因此 Google 徽标将不再位于屏幕的右下方。此外,所有注释视图都会旋转,并且在应用程序上看起来很奇怪。

有谁知道如何只旋转 MkMapView 的内容(街道画)?

谢谢

【问题讨论】:

    标签: iphone mkmapview rotation


    【解决方案1】:

    这是我旋转 MapView 的方式(请参阅 Rotate MapView using Compass orientation):

    [self.mapView setTransform:CGAffineTransformMakeRotation(-1 * currentHeading.magneticHeading * 3.14159 / 180)];
    

    然后将注释视图的方向与设备顶部保持一致:

    for (MKAnnotation *annotation in self.mapView.annotations) {
         MKAnnotationView *annotationView = [self.mapView viewForAnnotation:annotation]; 
         [annotationView setTransform:CGAffineTransformMakeRotation(currentHeading.magneticHeading * 3.14159 / 180)];
    }
    

    如果你想让annotationViews的旋转点是底部中心,我相信你会设置每个视图的anchorPoint如下:

      annotationView.layer.anchorPoint = CGPointMake(0.5, 1.0);
    

    我在执行此操作时仍然遇到一些关于 annotationView 位置更改的问题(可能与 * 问题相同的问题:changeing-my-calayers-anchorpoint-moves-the-view)。

    【讨论】:

    • 我正在根据 CoreLocation 检索的标题信息旋转 MapView 做类似的事情。我在 github 上的 MIT 下发布了它(还包括更有用的东西,例如 BarButtonItem,其行为类似于内置的 Google 地图应用程序之一)-github.com/myell0w/MTLocation
    • 尝试在 didUpdateHeading 中使用 newHeading 变量:(CLHeading *)newHeading 处理程序