gpt4 book ai didi

ios - map 上的 Swift 注释作为按钮

转载 作者:行者123 更新时间:2023-11-30 13:55:15 25 4
gpt4 key购买 nike

我尝试给我的注释添加 3 个按钮(2 个已经完成),图像上的按钮 1 和按钮 2 起作用,现在我想在单击按钮 3 后执行转场,有办法这样做吗?

enter image description here

要创建此注释,我的代码如下所示

if (annotation is CustomPointAnnotation2){

let reuseId = "ParseAnno"

var anView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
if anView == nil {
anView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
anView!.canShowCallout = true
}
else {
anView!.annotation = annotation
}

let buttonSignIcon1 = UIButton()
buttonSignIcon1.frame.size.width = 50
buttonSignIcon1.frame.size.height = 52
buttonSignIcon1.backgroundColor = UIColor(red: 0, green: 0.373, blue: 0.694, alpha: 1.0)
buttonSignIcon1.setImage(UIImage(named: "annotationButtonLeft"), forState: .Normal)
anView!.leftCalloutAccessoryView = buttonSignIcon1





let buttonSignIcon = UIButton()
buttonSignIcon.frame.size.width = 50
buttonSignIcon.frame.size.height = 52
buttonSignIcon.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1.0)
buttonSignIcon.setImage(UIImage(named: "annotationButtonRight"), forState: .Normal)
anView!.rightCalloutAccessoryView = buttonSignIcon

let x = annotation as! CustomPointAnnotation2
anView!.image = UIImage(named:x.imageName)


return (anView)

点击我使用的“运行函数”

func mapView(mapView: MKMapView!, annotationView: MKAnnotationView, calloutAccessoryControlTapped control: UIControl) {

if control == annotationView.leftCalloutAccessoryView {

print(annotationView.annotation?.title)
print(annotationView.annotation?.coordinate)
self.Destination_fromAnnotation = (annotationView.annotation?.coordinate)!
self.getDirections()
}
.
.
.

有没有办法让按钮“3”也有一个 Action ?

最佳答案

我认为建议为您的 MKAnnotationView 提供一个包含按钮的 subview 。

如果您可以使用左右标注附件以及 image 属性,那就没问题,但如果您需要更多(如您的情况),那么将所有内容嵌入到认为您进行设计而不是依赖于预配置的 UI 元素,这些元素很可能用于不同的用途。

事实上,尽管你的屏幕截图看起来很糟糕,尽管它拥有三色的荣耀,但由于对齐和间距不严密,这是自定义 View 的一个例子。

关于ios - map 上的 Swift 注释作为按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33709653/

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