Closed donbytyqi closed 7 years ago
on the cluster annotation or regular annotation?
on the cluster annotation view, sorry should've been more clear.
annotationView = ClusterAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier, type: .image(UIImage(named: "pin.png"))) annotationView?.isUserInteractionEnabled = true annotationView?.canShowCallout = true annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
You need to add it twice since its reused
if let view = view as? ClusterAnnotationView {
view.annotation = annotation
view.configure(with: type)
view.canShowCallout = true
view.rightCalloutAccessoryView = SomeView()
} else {
view = ClusterAnnotationView(annotation: annotation, reuseIdentifier: identifier, type: type)
view.canShowCallout = true
view.rightCalloutAccessoryView = SomeView()
}
That doesn't seem to work as well, is this the right place to put it?
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !annotation.isKind(of: MKUserLocation.self) else {
return nil
}
let annotationIdentifier = "AnnotationIdentifier"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)
if annotationView == nil {
annotationView = ClusterAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier, type: .image(UIImage(named: "pin.png")))
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
} else {
annotationView!.annotation = annotation
annotationView?.canShowCallout = true
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
}
return annotationView
}
I don't believe I'm breaking the callout anywhere. Can u check stackoverflow? Or try to debug it.
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
guard !annotation.isKind(of: MKUserLocation.self) else {
return nil
}
let annotationIdentifier = "AnnotationIdentifier"
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: annotationIdentifier)
if annotationView == nil {
annotationView = ClusterAnnotationView(annotation: annotation, reuseIdentifier: annotationIdentifier, type: .image(UIImage(named: "pin.png")))
} else {
annotationView!.annotation = annotation
}
annotationView!.canShowCallout = true
annotationView!.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
return annotationView
}
Still not working, maybe the issue is Swift 4?
swift 4 doesn't affect callouts
hmm, okay, I'll just see what's causing this issue. Thanks for the help :)
It breaks because of the layer.masksToBounds = true
in ClusterAnnotationView
I'm having the same issue. How can I display annotation callout? Can someone show me on example code from this repo? Thanks for help
This library handles the clustering, you can add a callout by using the MKMapViewDelegate methods.
Example: https://www.raywenderlich.com/548-mapkit-tutorial-getting-started
anyone have the solution?
annotation.canShowCallout = true annotation.rightCalloutAccessoryView = UIButton
Doesn't seem to work.