swift - 在 MKMapView 上更新用户位置的图像

标签 swift mkmapview mapkit mkannotationview

我正在为 map 上的用户位置设置自定义图像,如下所示:

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
}

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

最佳答案

这个解决方案对我有用:

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

关于swift - 在 MKMapView 上更新用户位置的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34315001/

相关文章:

javascript - 使用 iOS map 链接 api 在标记上设置标签

ios - 自定义委托(delegate)和数据源 NSObject 最佳实践

ios - Swift UIImage 转换为 PDF

iOS mapView animatesDrop

ios - MKMapView如何知道旋转角度?

ios - 如何自动缩放 mapView 以显示覆盖

ios - 为什么我无法自定义 MKAnnotationView?

ios - PHAssetResource.assetResources 使用有效的 PHAsset 返回零结果

swift - 为什么videoview宽度大小是一半?

ios - 在为其框架设置动画时禁用向 mapView 添加注释