我有一台带MKUserTrackingBarButtonItem的MKMapView。用户的当前位置应该只在Follow或FollowWithHeading模式下显示。其实现如下所示:
- (void)mapView:(MKMapView *)mapView
didChangeUserTrackingMode:(MKUserTrackingMode)mode
animated:(BOOL)animated
{
[mapView setShowsUserLocation:(mode != MKUserTrackingModeNone)];
}这是我的代码中唯一调用setShowsUserLocation的地方,当按下MKUserTrackingBarButtonItem时,它会正常工作。
我的问题发生在通过拖动地图更改UserTrackingMode时:在这种情况下,“蓝点”注释会按预期消失,但在大约20%的情况下,当拖动结束时,它会重新出现。
如果我随后测试地图的showsUserLocation属性,它总是被设置为NO,即使“蓝点”注释是可见的。
如果你知道如何解决这个问题,我将不胜感激。
发布于 2011-12-19 11:57:32
看起来,如果用户位置更新是在拖动过程中的某个时间进行的,那么即使showsUserLocation为NO,didUpdateUserLocation委托方法仍然会触发,并且蓝点会重新出现。
这似乎是地图视图的一个缺点。
在didUpdateUserLocation中切换showsUserLocation似乎可以修复地图视图的内部状态,蓝点也会消失:
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
if (!mapView.showsUserLocation)
{
mapView.showsUserLocation = YES;
mapView.showsUserLocation = NO;
}
}https://stackoverflow.com/questions/8555903
复制相似问题