gpt4 book ai didi

ios - 在自定义 MKPinAnnotationView 中显示注释标题和子标题

转载 作者:行者123 更新时间:2023-12-01 22:29:35 25 4
gpt4 key购买 nike

我正在使用 MKPinAnnotationView在我的应用程序中。

我正在设置 MapView对象作为委托(delegate),并使用此代码自定义我的 AnnotationView

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

if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location
return nil
}

let reuseId = "pin"

var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
// pinView!.canShowCallout = true
pinView!.image = UIImage(named:"store.jpg")
pinView!.animatesDrop = true
pinView!.pinTintColor = UIColor.darkGrayColor()
}
else {
pinView!.annotation = annotation
}

return pinView
}

我正在根据需要获取自定义 AnnotationView。但是,我缺少 title 的功能和 subtitleMKPointAnnotation .

我希望看到灰点的标题和副标题。 enter image description here

最佳答案

我正在覆盖一个功能

func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
mapView.deselectAnnotation(view.annotation, animated: true)
}

我把这个函数注释掉了,得到了标题和字幕。

更新代码
/*
func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) {
mapView.deselectAnnotation(view.annotation, animated: true)
}
*/
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location
return nil
}

let reuseId = "pin"
let pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView.canShowCallout = true
pinView.animatesDrop = true
pinView.pinTintColor = UIColor.darkGrayColor()
pinView.draggable = true
pinView.accessibilityLabel = "hello"
let btn = UIButton(type: .DetailDisclosure)
pinView.rightCalloutAccessoryView = btn
return pinView
}

关于ios - 在自定义 MKPinAnnotationView 中显示注释标题和子标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37964914/

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