gpt4 book ai didi

ios - 阻止 Mapkit 自定义 MKAnnotationView 在点击时消失

转载 作者:行者123 更新时间:2023-11-30 12:00:56 24 4
gpt4 key购买 nike

我目前在 map 标注中设置了一个自定义 MKAnnotationView,并且运行良好。然而,我想向标注 View 添加一个按钮,但是当我点击该按钮时,它会在调用之前关闭注释 View 。我该如何解决这个问题?

以下是我的代码的相关部分:在我看来,注释:

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) ->    MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}

let reuseId = "mapReuseId"
var mapView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId)
if mapView == nil {
mapView = MKAnnotationView(annotation: annotation as! Annotation, reuseIdentifier: reuseId)
mapView!.canShowCallout = false
} else {
mapView!.annotation = annotation as! Annotation
}
mapDottView!.image = customImage

return mapDottView
}

在我的 didSelect 委托(delegate)中:

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
let callOut = customCallOutView(with: data)
view.addSubview(callOut)
// some layout here
}

customCallOutView 有点长,但重要的是它有一个 UIButton,永远不会在点击时被调用。有什么想法吗?

最佳答案

您可以尝试在点击按钮时设置延迟。您可以使用Grand Central DispatchPerform Selector After Delay .

// Do what you need to do when your button was tapped.
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
// Dismiss your annotation.
}

关于ios - 阻止 Mapkit 自定义 MKAnnotationView 在点击时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47245447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com