【问题标题】:Erratic behavior of showsUserLocation in MKMapViewMKMapView 中的 showUserLocation 行为不稳定
【发布时间】:2023-03-09 13:32:01
【问题描述】:

我有一个MKMapView 和一个MKUserTrackingBarButtonItem。用户的当前位置只能在FollowFollowWithHeading 模式下显示。实现如下所示:

- (void)mapView:(MKMapView *)mapView 
didChangeUserTrackingMode:(MKUserTrackingMode)mode 
       animated:(BOOL)animated
{
    [mapView setShowsUserLocation:(mode != MKUserTrackingModeNone)]; 
}

这是我的代码中唯一调用setShowsUserLocation 的地方,当按下MKUserTrackingBarButtonItem 时它按预期工作。

UserTrackingMode 通过拖动地图更改时会出现我的问题:在这种情况下,“蓝点”注释会按预期消失,但在大约 20% 的情况下,它会在拖动结束后重新出现。

如果我随后测试地图的 showsUserLocation 属性,它始终设置为 NO,即使“蓝点”注释可见。

如果您知道如何解决此问题,我将非常感谢您的帮助。

【问题讨论】:

    标签: ios ios5 mkmapview


    【解决方案1】:

    看起来如果用户位置更新在拖动过程中的某个时间出现,didUpdateUserLocation 委托方法仍然会触发并且蓝点会重新出现,即使 showsUserLocationNO

    这似乎是地图视图的一个缺点。

    didUpdateUserLocation 中切换showsUserLocation 似乎修复了地图视图的内部状态并且蓝点消失了:

    -(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
    {
        if (!mapView.showsUserLocation)
        {
            mapView.showsUserLocation = YES;
            mapView.showsUserLocation = NO;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-12-07
      • 1970-01-01
      • 2011-04-24
      • 2011-01-27
      • 2019-08-02
      • 1970-01-01
      • 2012-04-24
      • 2015-08-19
      • 2020-09-13
      相关资源
      最近更新 更多