MKMapView:如何将 MKUserLocationView (蓝点)带到前面?
我正在添加自定义注释而不是引脚注释。 基本上,我在这些注释中画一个圆圈并将它们添加到地图中。 这些自定义注释模糊了用户位置视图的问题(蓝点) 如何将蓝点移到前面。
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { UIView *user = [mapView viewForAnnotation:userLocation]; [mapView bringSubviewToFront:user]; }
但是,这对我不起作用。蓝色的用户点仍然被我的自定义注释覆盖。 有什么想法可以让用户位置视图出现在前面吗? 干杯
I am adding a custom annotation instead of the pin annotation.
Basically, I draw a circle in these annotations and add them to the map.
THe problem these custom annotations obscure the user location view ( the blue dot)
How do I bring the blue dot to the front.
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { UIView *user = [mapView viewForAnnotation:userLocation]; [mapView bringSubviewToFront:user]; }
However, this is not working for me. The blue user dot is still being covered by my custom annotations.
Any ideas how I can get the user location view to appear in front?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个,它有效:
Try this, it works.:
我是这样完成的:
I accomplished it like this:
通常您希望 userLocation 视图位于后面。至少这是带有图钉的地图视图的正常行为。
如果你真的想把它放在前面,你必须找出真正的 userLocation 视图。我相信
[mapView viewForAnnotation:userLocation]
不会为您提供真正的 userLocation 视图(您检查过它不是nil
吗?)。我会向您的MKMapViewDelegate
添加一个-mapView:didAddAnnotationViews:
,如下所示:Normally you'd want to have the userLocation view in the back. At least that's the normal behavior for a mapView with pins.
If you really want to bring it to the front, you have to find out the real userLocation view. I believe
[mapView viewForAnnotation:userLocation]
doesn't give you the real userLocation view (have you checked it's notnil
?). I would add a-mapView:didAddAnnotationViews:
to yourMKMapViewDelegate
like this:奥特温的回答对我不起作用。 MKUserLocationView 从来不在该数组中(至少在我的测试中)。
相反,直接从 MKMapView 实例获取值。像这样:
“userLocationAnnotationView”是我的视图控制器中的一个ivar:
当您运行此代码时,当前位置视图必须已经添加。 viewDidLoad 中的情况可能并非如此,原因有多种,包括:a) 还没有 GPS 更新 b) 当前位置不在屏幕上。我正在运行此代码:
祝你好运!
Ortwin's answer did not work for me. The MKUserLocationView is never in that array (at least in my testing).
Instead, get the value from the MKMapView instance directly. Like so:
"userLocationAnnotationView" is an ivar I have in my view controller:
When you run this code, the current location view must have already been added. This may not be the case in viewDidLoad for a variety of reasons including: a) no GPS updates yet b) current location is off screen. I'm running this code in:
Good luck!