【发布时间】:2012-01-09 06:56:10
【问题描述】:
点击代表 userLocation 的脉动蓝色圆圈会弹出“当前位置”标注。有没有办法抑制它?
【问题讨论】:
标签: ios mkmapview mkmapviewdelegate
点击代表 userLocation 的脉动蓝色圆圈会弹出“当前位置”标注。有没有办法抑制它?
【问题讨论】:
标签: ios mkmapview mkmapviewdelegate
在用户位置更新后,您可以更改注释视图上的一个属性:
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKAnnotationView *userLocationView = [mapView viewForAnnotation:userLocation];
userLocationView.canShowCallout = NO;
}
【讨论】:
viewForAnnotation 中处理有效。
您可以将title 设置为空白以禁止标注:
mapView.userLocation.title = @"";
编辑:
更可靠的方法可能是在 didUpdateUserLocation 委托方法中将标题留空:
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
userLocation.title = @"";
}
或viewForAnnotation:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>) annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
((MKUserLocation *)annotation).title = @"";
return nil;
}
...
}
在委托方法中设置标题可让您确定您有一个真实的 userLocation 实例可供使用。
【讨论】:
mapView:didSelectedAnnotationView: 到被召唤?
斯威夫特 4
// MARK: - MKMapViewDelegate
func mapViewDidFinishLoadingMap(_ mapView: MKMapView) {
if let userLocationView = mapView.view(for: mapView.userLocation) {
userLocationView.canShowCallout = false
}
}
【讨论】:
mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) 回调中利用这一点,将其与所有其他注释视图组合在一起
Swift 4 - Xcode 9.2 - iOS 11.2
// MARK: - MKMapViewDelegate
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let userLocation = annotation as? MKUserLocation {
userLocation.title = ""
return nil
}
// ...
}
【讨论】:
我有两种方法可以帮助你:
在 mapViewDidFinishLoadingMap 中抑制
func mapViewDidFinishLoadingMap(_ mapView: MKMapView) {
mapView.showsUserLocation = true
//suppress the title
mapView.userLocation.title = "My Location"
//suppress other params
}
在 didUpdate 中抑制
func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) {
//suppress the title
mapView.userLocation.title = "My Location"
//suppress other params
}
【讨论】:
mapView添加用户MKAnnotationView时,我们需要将用户MKAnnotationView属性canShowCallout设置为false
func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
for view in views {
if view.annotation is MKUserLocation {
view.canShowCallout = false
}
}
}
【讨论】:
嘿,有一个更新的简单解决方案
斯威夫特:
mapView.userLocation.title = "";
.Net for iOS (Xamarin.iOS)
NativeMap.UserLocation.Title = "";
问候 ;)
【讨论】: