我正在制作一个显示用户当前位置的 MKMapView。 我想像 Google map 应用程序一样旋转 map ,但不旋转注释。我使用以下代码
-(void) locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
mapView.transform=CGAffineTransformMakeRotation(-1*newHeading.magneticHeading*3.14159/180)};
但是整个 View 像这个图像一样旋转。 The image of the problem in my app
最佳答案
您基本上需要对所有注释 View 应用相同的变换,但具有负角度,即
for (id<MKAnnotation> annotation in mapView.annotations)
{
MKAnnotationView* annotationView = [mapView viewForAnnotation:annotation];
[annotationView setTransform:CGAffineTransformMakeRotation(-angle)];
}
如果您计划添加更多注释,您也应该在 mapView:didAddAnnotationViews:
中放置相同的代码:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
for (MKAnnotationView* annotationView in views)
{
[annotationView setTransform:CGAffineTransformMakeRotation(-angle)];
}
}
关于iphone - 如何旋转MKMapView并保持Annotation和 View 不旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7036246/