Is there a way to set MKMap Overlay drawing frequency? In iOS 13, the frequency has been greatly reduced to save energy I guess. However I need higher frequency for better user interaction. Thanks.
MKMap Overlay drawing frequency
Hi, Unfortunately, animating overlays by repeatedly calling func setNeedsDisplay(_ mapRect: MKMapRect) isn't really something that we support. While you can change your overlay this way, it isn't guaranteed to run at a smooth frame rate (and in fact, as you can see, probably won't). That said, it is something that many developers want to do, and we did make some changes in iOS 13.5 that should have improved the behavior in this area.
I can suggest a workaround though. If you create your own CALayer or UIView, and insert it into your hierarchy above the MKMapView, you'll be able to draw to that layer as fast as you like. You can get updates when the map view changes its visible region via func mapViewDidChangeVisibleRegion(MKMapView) on your MKMapViewDelegate implementation. If you want to continue to load your data in tiles, I can recommend using CATiledLayer to make this easier. Unfortunately you’ll need to do a little more math yourself to figure out the correct position of each tile though.
Finally, overlays that animate are certainly a feature that many people ask for. Could I get you to file an enhancement request in the Feedback Assistant that documents your use case (for example, are you using image overlays, or geometric overlays? Do you have a series of key frames you need to animate through, or do you draw new content every frame? Etc). With that feedback we can understand the set of use cases that developers need support for if we add animated overlay support in the future.
I can suggest a workaround though. If you create your own CALayer or UIView, and insert it into your hierarchy above the MKMapView, you'll be able to draw to that layer as fast as you like. You can get updates when the map view changes its visible region via func mapViewDidChangeVisibleRegion(MKMapView) on your MKMapViewDelegate implementation. If you want to continue to load your data in tiles, I can recommend using CATiledLayer to make this easier. Unfortunately you’ll need to do a little more math yourself to figure out the correct position of each tile though.
Finally, overlays that animate are certainly a feature that many people ask for. Could I get you to file an enhancement request in the Feedback Assistant that documents your use case (for example, are you using image overlays, or geometric overlays? Do you have a series of key frames you need to animate through, or do you draw new content every frame? Etc). With that feedback we can understand the set of use cases that developers need support for if we add animated overlay support in the future.
Here is my user case, I need to draw a few geometric overlays when use tap the screen. And I also need to move the overlays when user moves the finger. Basically I remove the overlays and re-create new overlays. So basically I draw new content every frame?
I will file an enhancement request. Thanks.
I will file an enhancement request. Thanks.