如何旋转的MKMapView并保持注解和视图不旋转? [英] How to rotate MKMapView and keep the Annotation and the view don't rotate?

查看:149
本文介绍了如何旋转的MKMapView并保持注解和视图不旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我作出的MKMapView,显示用户的当前位置。
我想旋转地图,如谷歌地图应用程序不旋转的注解。使用以下code IM

I am making an MKMapView that shows the user's current location. I want to rotate the map like the Google Maps App without rotating the annotations. Im using the following code

-(void) locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
     mapView.transform=CGAffineTransformMakeRotation(-1*newHeading.magneticHeading*3.14159/180)};

但整个视图旋转,这样的形象。
问题的形象在我的应用程序

推荐答案

您基本上需要应用相同的转换所有注解意见,但有负角度,即

You basically need to apply a the same transform to all annotation views but with negative angle, i.e.

for (id<MKAnnotation> annotation in mapView.annotations) 
{
    MKAnnotationView* annotationView = [mapView viewForAnnotation:annotation];
    [annotationView setTransform:CGAffineTransformMakeRotation(-angle)];
}

如果您打算增加更多的注解,你应该把在 MapView可以在同一code:didAddAnnotationViews:太:

If you're planning to add more annotations you should place the same code in mapView:didAddAnnotationViews: too:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    for (MKAnnotationView* annotationView in views) 
    {
        [annotationView setTransform:CGAffineTransformMakeRotation(-angle)];
    }
}

这篇关于如何旋转的MKMapView并保持注解和视图不旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆