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

Ele*_*ron 5 iphone objective-c rotation mkmapview ios

我试图得到它,以便当您旋转iOS 7地图时,注释随着相机标题一起旋转.想象一下,我的引脚注释必须始终指向North.

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

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

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)

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

到目前为止,我最成功的方法是添加一个旋转手势识别器来计算旋转增量,并将其与区域更改代表开头报告的摄像头标题一起使用.这可以达到一定的目的,但在OS 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];
}
Run Code Online (Sandbox Code Playgroud)

Ros*_*mes 3

不幸的是,苹果不提供任何地图信息的实时更新。您最好的选择是设置一个 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];
}
Run Code Online (Sandbox Code Playgroud)