gpt4 book ai didi

swift - MKPointAnnotation如何隐藏标记图像

转载 作者:行者123 更新时间:2023-11-30 10:34:21 25 4
gpt4 key购买 nike

我有一个已设置的MKPointAnnotation,它显示在我想要的位置,但是它在点上带有默认的大红色图钉图标,我想隐藏该图像并显示什么也没有代替。我尝试过使用下面用“*****”评论的部分,我认为可能有效的是设置 view.image=nil 这并没有改变任何东西,我也尝试过view.frame.size=CGSize(width: 0, height: 0) 没有任何效果。关于如何实现这一目标还有其他建议吗?

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

let annotation = annotation

let identifier = "marker"
var view: MKMarkerAnnotationView


if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
as? MKMarkerAnnotationView {
dequeuedView.annotation = annotation
view = dequeuedView
} else {
//************************
view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.frame.size=CGSize(width: 0, height: 0)
view.canShowCallout = true
view.calloutOffset = CGPoint(x: -5, y: 5)
view.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)



}
return view
}

最佳答案

这实际上比我预期的更容易解决,我所需要做的就是将 markerTintColor 设置为 alpha 为 0 的颜色。

view.markerTintColor=UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0,alpha:0.5).withAlphaComponent(0)

在这种情况下为我解决了这个问题。

关于swift - MKPointAnnotation如何隐藏标记图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58402704/

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