Iphone 根据设备标题旋转MKAnnotationPinView

Iphone 根据设备标题旋转MKAnnotationPinView,iphone,annotations,mkmapview,mkpinannotationview,Iphone,Annotations,Mkmapview,Mkpinannotationview,在我的应用程序中,我根据设备标题旋转地图视图,我只有一个注释,我旋转它的pin和pinView。 我的旋转方法在下一个函数中 - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { if (newHeading.headingAccuracy < 0) return; CLLocationDirection theHeading = ((new

在我的应用程序中,我根据设备标题旋转地图视图,我只有一个注释,我旋转它的pin和pinView。 我的旋转方法在下一个函数中

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
if (newHeading.headingAccuracy < 0)
    return;

CLLocationDirection  theHeading = ((newHeading.trueHeading > 0) ?
                                   newHeading.trueHeading : newHeading.magneticHeading);

lastHeading = theHeading;
[self rotateImage:self.mapView duration:0.1 degrees:-theHeading];

[self rotateImage:jerusalemPinView duration:0.1 degrees:theHeading];

}    
它正在工作,但是annotation和pinView总是“尝试返回北方”,然后下次当设备转过来时,我的方法会工作,等等。。 我错过了什么


谢谢

旋转jerusalemPinView后,视图是否会被viewForAnnotation重新绘制?我建议在重要方法的顶部放一行调试代码,并检查它们被调用的顺序。我的猜测是,在viewForAnnotation中,您创建一个新的jerusalemPinView,将其分配给pin,然后调用didUpdateHeading并旋转它,然后再次调用viewForAnnotation并再次创建一个新的(未旋转的)jerusalemPinView。

旋转jerusalemPinView后,视图是否会被viewForAnnotation重绘?我建议在重要方法的顶部放一行调试代码,并检查它们被调用的顺序。我的猜测是,在viewForAnnotation中,您创建一个新的jerusalemPinView,将其分配给pin,然后调用didUpdateHeading并旋转它,然后viewForAnnotation再次调用,并再次创建一个新的(未旋转的)jerusalemPinView。

我不完全理解。你是说它第一次不起作用,但之后就起作用了?新尝试的定义是什么?这是对didUpdateHeading的新调用吗?让我们看看你在那个函数中的代码,用代码编辑。它工作了,然后又往北跳,我不太明白。你是说它第一次不起作用,但之后就起作用了?新尝试的定义是什么?这是对didUpdateHeading的新调用吗?让我们看看你在那个函数中的代码,用代码编辑。它工作了,然后又往北跳
- (void)rotateImage:(UIView *)view duration:(NSTimeInterval)duration
        degrees:(double)angleDegrees
{

// Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationBeginsFromCurrentState:YES];

// The transform matrix

CGAffineTransform transform =
CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(angleDegrees));
view.transform = transform;

[UIView commitAnimations];
}