swiftui-mapkit-callout icon indicating copy to clipboard operation
swiftui-mapkit-callout copied to clipboard

Callout View is misplaced after map is dragged

Open zulfishah opened this issue 3 years ago • 5 comments

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: Screen Shot 2021-03-26 at 6 30 34 PM

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 avatar Mar 27 '21 01:03 zulfishah

@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?

khuffie avatar Mar 30 '21 20:03 khuffie

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.

zulfishah avatar Apr 01 '21 00:04 zulfishah

@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! Screenshot 2022-11-14 at 7 47 49 AM

jung-joseph avatar Nov 14 '22 14:11 jung-joseph

@jung-joseph - of course, you're welcome to use it!

khuffie avatar Nov 14 '22 14:11 khuffie

Could you please add a license file (e.g. MIT license) ?

raybellis avatar Nov 29 '22 16:11 raybellis