Description
Hi. I have implemented a custom view for un-clustered annotations, and I'm noticing that it is impossible to tap them, aka, buttons are unclickable in the annotation. I am working in SwiftUI, making my view a MKMapViewRepresentable to wrap the UIKit components, and calling the different views like so:
With my CustomAnnotationView looking like this to call AnnotationView (which is my true custom display)
override var annotation: MKAnnotation? {
willSet {
hostingController?.view.removeFromSuperview()
hostingController = nil
if let customAnnotation = newValue as? CustomAnnotation {
let annotationView = AnnotationView(region: region, annotation: customAnnotation)
let hostingController = UIHostingController(rootView: annotationView)
hostingController.view.frame = self.bounds
hostingController.view.backgroundColor = UIColor.clear
hostingController.view.isUserInteractionEnabled = true
self.addSubview(hostingController.view)
self.hostingController = hostingController
}
}
In the AnnotationView, I have a button in the ZStack, whose action never gets called when tapped. I have tried all sorts of work arounds like making other things in the Stack ontapGesture but annotations just don't seem to be tappable when the library is wrapped in all these UIKit things when used in SwiftUI.
Description Hi. I have implemented a custom view for un-clustered annotations, and I'm noticing that it is impossible to tap them, aka, buttons are unclickable in the annotation. I am working in SwiftUI, making my view a MKMapViewRepresentable to wrap the UIKit components, and calling the different views like so:
With my CustomAnnotationView looking like this to call AnnotationView (which is my true custom display)
In the AnnotationView, I have a button in the ZStack, whose action never gets called when tapped. I have tried all sorts of work arounds like making other things in the Stack ontapGesture but annotations just don't seem to be tappable when the library is wrapped in all these UIKit things when used in SwiftUI.
Checklist