根据设备航向旋转MKAnnotationPinView [英] Rotate MKAnnotationPinView according to the device heading

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

问题描述

在我的应用程序,我会根据设备标题旋转的MapView,我只有一个注解,我旋转它的脚,它的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后,不认为得到由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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆