我正在制作一个显示用户当前位置的 MKMapView。
我想像 Google 地图应用程序一样旋转地图,但不旋转注释。我使用以下代码
-(void) locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading{
mapView.transform=CGAffineTransformMakeRotation(-1*newHeading.magneticHeading*3.14159/180)};
但整个视图像这个图像一样旋转。我的应用程序中问题的图像 http://dl.dropbox.com/u/22880687/Screenshot.png
您基本上需要对所有注释视图应用相同的变换,但具有负角度,即
for (id<MKAnnotation> annotation in mapView.annotations)
{
MKAnnotationView* annotationView = [mapView viewForAnnotation:annotation];
[annotationView setTransform:CGAffineTransformMakeRotation(-angle)];
}
如果您打算添加更多注释,您应该将相同的代码放在mapView:didAddAnnotationViews:
too:
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
for (MKAnnotationView* annotationView in views)
{
[annotationView setTransform:CGAffineTransformMakeRotation(-angle)];
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)