本文介绍了根据设备标题旋转 MKAnnotationPinView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我根据设备标题旋转 MapView,我只有一个注释,而且我正在旋转它的 pin 和 pinView.我的旋转方法在​​下一个函数内

In my app I'm rotating the MapView according to the device heading, I have only one annotation and i'm rotating it's pin and it's pinView too.My rotation method is inside the next function

- (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];

}

旋转功能:

- (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];
}

它正在工作,但是注释和 pinView 总是尝试转向北方",然后下一次当设备转向我的方法工作时等等..我错过了什么?

it's working but then annotation and pinView are always "try to turn back to the north", then the next time when the device is being turned around my method works and so on..What am i missing?

谢谢

推荐答案

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

After rotating jerusalemPinView, does the view get redrawn by viewForAnnotation? I suggest putting a debug line at the top of the important methods and checking what order they are getting called in. My guess is that in viewForAnnotation you make a new jerusalemPinView, assign it to the pin, then didUpdateHeading gets called and your rotate it, then viewForAnnotation gets called again and a new (unrotated) jerusalemPinView is made again.

这篇关于根据设备标题旋转 MKAnnotationPinView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:23