【问题标题】:Update image for user location on MKMapView更新 MKMapView 上用户位置的图像
【发布时间】:2015-12-16 14:46:35
【问题描述】:

我在这样的地图上为用户位置设置自定义图像:

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    if annotation.isEqual(mapView.userLocation) {

        let identifier = "User"

        var annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(identifier)

        if annotationView == nil{
            annotationView = CustomPointAnnotation(annotation: annotation, reuseIdentifier: identifier)
            annotationView!.canShowCallout = true

        } else {
            annotationView!.annotation = annotation
        }

        annotationView!.image = UIImage(named: userImage)

        return annotationView

    }
    return nil
}

我更改了图像属性,如何告诉地图更新 MKAnnotationView?

【问题讨论】:

    标签: swift mkmapview mapkit mkannotationview


    【解决方案1】:

    这个解决方案对我有用:

    let userLocation = mapView.view(for: mapView.userLocation)
    userLocation?.image = UIImage(named: "newImage")
    userLocation?.isHidden = true
    userLocation?.isHidden = false
    

    【讨论】:

      【解决方案2】:

      我的一个答案 - https://stackoverflow.com/a/57868438/7505665

      我有类似的问题和解决方案是这段代码

      self.mapView.showsUserLocation = false
      self.mapView.showsUserLocation = true
      

      【讨论】:

        【解决方案3】:

        我认为您想删除注释,然后重新添加它们,这将强制地图更新。直接编辑现有注释不会强制重绘地图。

        【讨论】:

          猜你喜欢
          • 2011-09-18
          • 1970-01-01
          • 1970-01-01
          • 2013-01-03
          • 2016-08-22
          • 2011-09-11
          • 2011-08-16
          • 2013-04-17
          • 2011-08-29
          相关资源
          最近更新 更多