仅旋转MapView的内容

仅旋转MapView的内容

本文介绍了仅旋转MapView的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to rotate a map view in my app according the the user's current route. (I don't like to use the built in compasse because only 3GS uses it and it suffers too much interference from other machines, i.e. your own car.).

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

the CGAffineTransformMakeRotation method will rotate the Whole Map View, so the Google Logo will not be in the lower right of the screen anymore. Also all Annotation Views will rotate and look weird on the App.

有人知道如何仅旋转MkMapView的内容(街道)吗?

Does anyone knows how to rotate just the content (streets drwaings) of the MkMapView?

谢谢

推荐答案

这是我旋转MapView的方式(请参见):

Here is how I'm rotating the MapView (see Rotate MapView using Compass orientation):

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

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

Then to keep the orientation of the annotation views with the top of the device:

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

如果您想将annotationViews的旋转点作为底部中心,我相信您可以将每个视图的anchorPoint设置如下:

If you want the point of rotation of the annotationViews to be say the bottom center, I believe you would set each view's anchorPoint as follows:

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

尽管如此,我仍然在批注视图位置更改方面遇到一些问题(可能与stackoverflow问题相同:更改我的calayers-anchorpoint-移动视图-视图).

I'm still having some issues with the annotationView position changing when I do this though (probably same problem as stackoverflow question: changing-my-calayers-anchorpoint-moves-the-view).

这篇关于仅旋转MapView的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 05:36