swiftui-mapkit-callout
swiftui-mapkit-callout copied to clipboard
Callout View is misplaced after map is dragged
Hi, I'm trying to use this to add a SwiftUI view to the MKAnnotationView's detailCalloutAccessoryView. It works fine at first, but if the annotation is presented and the user drags the MKMapView around, the callout bubble looks fine but the detailCalloutAccessoryView doesn't move along with it! With views with buttons on it, it becomes a problem since the tap targets are different than what is showing on screen.
This is from the sample code, after dragging the map while the button test was visible:
The only work-around I've found so far is to detect the drags in MKMapView's regionDidChangeAnimated delegate call and then de-select the selected annotation. But it's not idea.
Any idea how to fix this properly?
@zulfishah to be honest, I don't have a lot of experience with UIKit. From what I can see, your app is UIKit based, and you're trying to add a SwiftUI view as an annotation to a map.
I only really learned SwiftUI, and I wanted the ability to add a SwiftUI view as an annotation to the map since it wasn't supported by default and I wasn't familiar with UIKit views.
Since your app is UIKit based, any reason why you're not using a UIView as a callout?
I wanted to create a SwiftUI view so I can share the same content view in both my UIKit and AppKit apps, and not have to recreate it twice. It works fine for that purpose, other than issue. For now, I am deselecting the annotation in regionWillChangeAnimated, and reselecting it in regionDidChangeAnimated, but it sucks for the user experience. BTW, the same issue doesn't happen on the AppKit side, and it works fine even after moving the map around! So it might well be a UIKit specific issue.
@khuffie, First I want to thank you for posting your cleaver solution to a vexing problem! I was struggling to create a flexible map callout view in my SwiftUI based map app that uses a MapView: UIViewRepresentable. I can also report that the callout view does not suffer from not being attached to the map, as reported by @zulfishah in his particular usage.
I am writing because I see that you have marked your MapCalloutView class code as Copyrighted. I am asking permission to use the code for that class directly. Thank you again!
@jung-joseph - of course, you're welcome to use it!
Could you please add a license file (e.g. MIT license) ?