【发布时间】:2021-04-17 21:31:50
【问题描述】:
这是我的 imageFor Mapbox 函数:
func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
var reuseid = ""
switch annotation.subtitle ?? "" {
case "uno":
reuseid = "uno"
case "dos":
reuseid = "dos"
case "tres":
reuseid = "tres"
default:
reuseid = "default"
}
var annotationImage = mapView.dequeueReusableAnnotationImage(withIdentifier: reuseid)
if annotationImage == nil {
guard let image = UIImage(named: reuseid) else { return nil }
annotationImage = MGLAnnotationImage(image: image, reuseIdentifier: reuseid)
let tapGesture = AnnotationTapGestureRecognizer(target: self, action: #selector(Coordinator.tappedAnnotation(sender:)))
tapGesture.annotation = annotation as! MGLPointAnnotation
annotationImage.addGestureRecognizer(tapGesture) //error on this line says 'Value of type 'MGLAnnotationImage?' has no member 'addGestureRecognizer''
}
return annotationImage
}
class AnnotationTapGestureRecognizer: UITapGestureRecognizer {
var annotation = MGLPointAnnotation()
}
如何制作,以便将手势识别器添加到要返回的 annotationImage 中?
【问题讨论】:
标签: swift mapbox uigesturerecognizer gesture uitapgesturerecognizer