Hi team, I've been trying to extend the animation when we call the function setVisibleMapRect, we can use UIView.animate to lengthen the animation time, but one thing that I found not working is that when I extend the animation to 3, 5, or 10 seconds, and the changes is still ongoing and there's a gesture performed, the map will completely ignore the gesture. Causing the map to be having this kind of like "delayed" or "freeze" experience for the user. The map will immediately move to the final rect and ignores the user gesture.
I've been checking on this problem for a week now and I'm quite stuck. I've tried using CADisplayLink to manually animate the camera per system fresh rate, it works very well, I can stop the camera movement anytime there are touches, but it causes the resource CPU spikes.
Removing the animation layers recursively on sublayers and subviews also doesn't help. While storing the animation into a UIViewPropertyAnimator and use stopAnimation will always ignores user first interactions too while also animating the camera to the final position (which is not expected).
There is a good example of animating a map using MKMapCamera in our Look Around sample code project. Using the map camera gives you better control over writing your own animation sequences, as the animations provided by setting the animation parameter of setVisibleMapRect to true will be decided by the system. However, as you found, those animations are effectively non-interruptible in practice due to how MapKit manages animations, regardless if you use the UIView family of animation methods, or UIViewPropertyAnimator. Enhancement requests for better integration across the animation APIs are welcomed!
I've tried using CADisplayLink to manually animate the camera per system fresh rate, it works very well, I can stop the camera movement anytime there are touches, but it causes the resource CPU spikes.
While you can use CADisplayLink to control rendering of any UIView on a frame-by-frame basis, you have to keep in mind the stringent performance targets you need to hit in order to not introduce perceivable frame drops. CADisplayLink runs at the display refresh rate, so on devices with a ProMotion display, the display refreshes at 120 Hz, or 120 times every 1,000 milliseconds. That means you have 8.33 ms to render every frame. This can be very difficult to get right, and means you have to be extremely diligent about deferring any non-essential work off the main thread to make sure your main thread can hit those deadlines, so in general, I don't suggest taking this approach due to the difficulty of pulling it off well. I can't comment directly on the CPU spikes directly since it's been some time since I last looked at doing something like this, but I hope your experiences discovering details like that illustrates why this requires detailed engineering diligence to maintain performance.
Removing the animation layers recursively on sublayers and subviews also doesn't help.
In general, you should avoid tinkering with the subviews or sublayers of any views other than your own.
— Ed Ford, DTS Engineer