Hide MKUserLocation when MKMapView showsUserLocation == YES

微笑、不失礼 提交于 2019-11-30 15:26:41

问题


After setting mapView.showsUserLocation to true, is it possible to receive location updates without showing the MKUserLocation bubble? Returning nil in mapView:viewForAnnotation: simply shows the bubble, and returning any other kind of annotation shows an annotation, which I don't want.


回答1:


You can hide the user location's view in the didAddAnnotationViews delegate method:

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *ulv = [mapView viewForAnnotation:mapView.userLocation];
    ulv.hidden = YES;
}



回答2:


Swift 3:

func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
   if let userLocation = mapView.view(for: mapView.userLocation) {
        userLocation.isHidden = true
   }
}


来源:https://stackoverflow.com/questions/9711874/hide-mkuserlocation-when-mkmapview-showsuserlocation-yes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!