gpt4 book ai didi

ios - 在 calloutAccessoryControlTapped 上检测仅点击 rightCalloutAccessoryView

转载 作者:IT王子 更新时间:2023-10-29 05:27:45 25 4
gpt4 key购买 nike

我的 calloutAccessoryControlTapped 当我点击注释 View 和 this behavior it's right 时也会被调用.但是我如何检测用户是否点击了正确的附件 View (在我的例子中是详细信息披露按钮)而不仅仅是在 View 中?

我添加了一个简单的检查,但它不起作用。

import UIKit
import MapKit

extension MapVC: MKMapViewDelegate, CLLocationManagerDelegate
{
func mapView(mapView: MKMapView, annotationView view: MKAnnotationView, calloutAccessoryControlTapped control: UIControl)
{
if control == view.rightCalloutAccessoryView
{
... // enter here even if I tapped on the view annotation and not on button
}
}

}

最佳答案

要实现它,您需要为正确的附件 View 添加目标。您可以通过将按钮设置为 rightCalloutAccessoryView 来实现它,如代码片段所示。

class MapViewController: UIViewController, MKMapViewDelegate {

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is Annotation {
let annotationView = AnnotationView(annotation: annotation, reuseIdentifier: "reuseIdentifier")
let rightButton = UIButton(type: .DetailDisclosure)
rightButton.addTarget(self, action: #selector(didClickDetailDisclosure(_:)), forControlEvents: .TouchUpInside)
annotationView.rightCalloutAccessoryView = rightButton
}
return nil
}

func didClickDetailDisclosure(button: UIButton) {
// TODO: Perform action when was clicked on right callout accessory view.
}
}

// Helper classes.
class Annotation: NSObject, MKAnnotation {
var coordinate: CLLocationCoordinate2D
var title: String?
var subtitle: String?

init(coordinate: CLLocationCoordinate2D, title: String, subtitle: String) {
self.coordinate = coordinate
self.title = title
self.subtitle = subtitle
}
}

class AnnotationView: MKAnnotationView {

}

关于ios - 在 calloutAccessoryControlTapped 上检测仅点击 rightCalloutAccessoryView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37010272/

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