在iOS 7地图相机旋转上更新地图注释

我正在尝试获取它,以便在旋转iOS 7地图时,注释随相机标题一起旋转。 想象一下,我有针标注必须始终指向北方。

这看起来很简单,首先,应该有一个MKMapViewDelegate获取相机旋转,但没有。

我已经尝试使用地图代表然后查询地图视图的camera.heading对象,但首先这些代表似乎只是在旋转手势之前和之后调用一次:

 - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated 

我也尝试在camera.heading对象上使用KVO,但这不起作用,并且相机对象似乎是某种只在旋转手势完成时才更新的代理对象。

到目前为止,我最成功的方法是添加旋转手势识别器来计算旋转增量,并将其与在区域更改代表开始时报告的摄像头标题一起使用。 这可以工作到一个点,但在操作系统7中,你可以“轻弹”你的旋转手势,它增加了我似乎无法跟踪的速度。 有没有办法实时跟踪摄像头的方向?

 - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated { heading = self.mapView.camera.heading; } - (void)rotationHandler:(UIRotationGestureRecognizer *)gesture { if(gesture.state == UIGestureRecognizerStateChanged) { CGFloat headingDelta = (gesture.rotation * (180.0/M_PI) ); headingDelta = fmod(headingDelta, 360.0); CGFloat newHeading = heading - headingDelta; [self updateCompassesWithHeading:actualHeading]; } } - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { [self updateCompassesWithHeading:self.mapView.camera.heading]; } 

不幸的是,苹果公司并没有给出任何地图信息的实时更新。 您最好的select是设置一个CADisplayLink,并在更改时更新所需的任何内容。 像这样的东西。

 @property (nonatomic) CLLocationDirection *previousHeading; @property (nonatomic, strong) CADisplayLink *displayLink; - (void)setUpDisplayLink { self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkFired:)]; [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; } - (void)displayLinkFired:(id)sender { double difference = ABS(self.previousHeading - self.mapView.camera.heading); if (difference < .001) return; self.previousHeading = self.mapView.camera.heading; [self updateCompassesWithHeading:self.previousHeading]; }