当我只点击注释视图和
this behavior it’s right时,我的calloutAccessoryControlTapped也被调用.但是如何检测用户是否在右侧的附件视图(在我的例子中是详细的公开按钮),而不仅仅是在视图中?
我添加了一个简单的检查,但它不工作.
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 } } }
解决方法
要实现它,您需要添加正确的配件视图的目标.您可以通过将代码片段中所示的按钮设置为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 { }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。