【问题标题】:MKMapView setVisibleMapRect edgePadding changes Camera heading when AnimatingMKMapView setVisibleMapRect edgePadding 在动画时更改相机标题
【发布时间】:2019-01-29 16:05:32
【问题描述】:

我正在通过调整 edgePadding 为 MKMapView 设置动画;但是,在制作动画时,地图会在动画期间旋转,并且 mapView 的现有摄像头在动画期间会丢失。

恢复标题并不理想;并且在动画期间设置相机航向会破坏动画并且不执行动画;方向仍然存在,但偏移量未设置动画。

下面的代码sn-p有动画地图偏移的效果,只是地图航向是翻转的;当动画完成时,我会修复标题。

我希望地图视图的标题保持原样,并且只为偏移设置动画 在调整 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;
}];

【问题讨论】:

    标签: objective-c mapkit mkmapview


    【解决方案1】:

    这是一个通过捕获 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
    }];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 2015-07-20
      • 1970-01-01
      相关资源
      最近更新 更多