代码之家  ›  专栏  ›  技术社区  ›  Wayne

MKMapView setVisibleMapRect edgeadding在设置动画时更改摄影机标题

  •  0
  • Wayne  · 技术社区  · 6 年前

    我正在通过调整edgePadding设置MKMapView的动画;但是,在执行动画时,贴图是 在动画过程中,地图视图的现有摄影机标题将丢失。

    下面的代码片段具有设置贴图偏移动画的效果,只是贴图标题被翻转;当动画完成时,我修复标题。

    请协助

    self.mapView.rotateEnabled = YES;
    self.mapView.camera.heading = deg;
    
    [MKMapView animateWithDuration:0.4 animations:^{
        // top, left, bottom, right
        self.mapView.layoutMargins = UIEdgeInsetsMake(y, 0, -y, 0);
        [self.mapView setVisibleMapRect:[self.mapView visibleMapRect]
                            edgePadding:UIEdgeInsetsMake(self.offset, 0.0, 0.0, 0.0)
                               animated:YES];
    } completion:^(BOOL finished) {
        self.mapView.camera.heading = deg;
        self.mapView.rotateEnabled = NO;
    }];
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Wayne    6 年前

    这里是一个工作的解决方案,通过捕捉MkMapViews当前的相机 以及在动画中设置MKMapViews摄影机。

    MKMapCamera *mapCamera = [[self.mapView camera] copy]; // the fix 1 of 2   
    [UIView animateWithDuration:0.4 animations:^{
        // top, left, bottom, right
        self.mapView.layoutMargins = UIEdgeInsetsMake(y, 0, -y, 0);
        [self.mapView setVisibleMapRect:[self.mapView visibleMapRect]
                            edgePadding:UIEdgeInsetsMake(self.offset, 0.0, 0.0, 0.0)
                               animated:YES];
        [self.mapView setCamera:mapCamera]; // the fix 2 of 2
    }];