Swift 映射框-calloutAccessoryControllerTapped
我的Callout AccessoryController出现问题。目前,我的标注中有两个按钮,每个按钮都会在地图视图上显示一个模式弹出窗口。此时我的segue工作,但两个按钮都切换到同一个弹出窗口。我需要能够区分按钮和它们的顺序 这可能吗?我在谷歌上搜索了这个问题,很多答案似乎都建议使用下面这行代码Swift 映射框-calloutAccessoryControllerTapped,swift,annotations,segue,mapbox,callout,Swift,Annotations,Segue,Mapbox,Callout,我的Callout AccessoryController出现问题。目前,我的标注中有两个按钮,每个按钮都会在地图视图上显示一个模式弹出窗口。此时我的segue工作,但两个按钮都切换到同一个弹出窗口。我需要能够区分按钮和它们的顺序 这可能吗?我在谷歌上搜索了这个问题,很多答案似乎都建议使用下面这行代码 if (control == view.leftCalloutAccessoryView) { 但是,出现了一个错误“类型为“UIView”的值没有成员“LeftCallout Accessor
if (control == view.leftCalloutAccessoryView) {
但是,出现了一个错误“类型为“UIView”的值没有成员“LeftCallout AccessoryView”。如果有人能帮我解决这个问题,我将不胜感激,如果我没有清楚地解释这个问题,我会道歉,我已经尽了最大的努力
下面是我的代码:
func mapView(_ mapView: MGLMapView, annotationCanShowCallout annotation: MGLAnnotation) -> Bool {
return true
}
func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {
self.performSegue(withIdentifier: "Show", sender: view)
}
func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
guard let skateAnnotation = annotation as? SkateAnnotation else { return nil }
if skateAnnotation.canEdit {
return UIButton(type: .detailDisclosure)
}
return nil
}
func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
return UIButton(type: .contactAdd)
}
func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
return nil
}
}
类似这样的简单操作(根据需要更改代码以满足您自己的需求)可以区分左侧和右侧详图索引附件控件
func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
let button = UIButton(type: .detailDisclosure)
button.tag = 100
return button
}
func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
let button = UIButton(type: .detailDisclosure)
button.tag = 101
return button
}
func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {
// Hide the callout view.
mapView.deselectAnnotation(annotation, animated: false)
if control.tag == 100 {
print("left")
} else if control.tag == 101 {
print("right")
}
}
类似这样的简单操作(根据需要更改代码以满足您自己的需求)可以区分左侧和右侧详图索引附件控件
func mapView(_ mapView: MGLMapView, leftCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
let button = UIButton(type: .detailDisclosure)
button.tag = 100
return button
}
func mapView(_ mapView: MGLMapView, rightCalloutAccessoryViewFor annotation: MGLAnnotation) -> UIView? {
let button = UIButton(type: .detailDisclosure)
button.tag = 101
return button
}
func mapView(_ mapView: MGLMapView, annotation: MGLAnnotation, calloutAccessoryControlTapped control: UIControl) {
// Hide the callout view.
mapView.deselectAnnotation(annotation, animated: false)
if control.tag == 100 {
print("left")
} else if control.tag == 101 {
print("right")
}
}
非常感谢!这正是我想要的,我非常感谢!如果你不介意,请接受答案。这一切都很有帮助:)甚至没有意识到stack overflow有这个问题!我是新手!非常感谢!这正是我想要的,我非常感谢!如果你不介意,请接受答案。这一切都有帮助:)有我甚至没意识到堆栈溢出有那个!我是新来的!