如何旋转 MKMapView 并保持注释和视图不旋转? [英] How to rotate MKMapView and keep the Annotation and the view don't rotate?
本文介绍了如何旋转 MKMapView 并保持注释和视图不旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在制作一个显示用户当前位置的 MKMapView.我想像谷歌地图应用程序一样旋转地图而不旋转注释.我使用以下代码
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)};
但整个视图像这张图片一样旋转.我的应用中问题的图像
but the whole view is rotated like this image. The image of the problem in my app
推荐答案
您基本上需要对所有注释视图应用相同的变换,但具有负角,即
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: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屋!
查看全文