含MKMapView的模态视图交互式关闭时动画冻结问题求助
Hi there, I've run into exactly this issue on iPhone 11 devices too, and can confirm it's reproducible following your steps (I think you meant MKMapView instead of MKWebView in your description—easy typo!).
Reproduction Confirmation
Yep, this bug pops up consistently when:
- You build a modal VC with just a navigation bar and
MKMapViewvia Storyboard - Present it modally from another VC (non-full-screen presentation)
- Try to dismiss with an interactive gesture (like swipe down)
The animation freezes mid-transition, and it's definitely not a performance issue since the iPhone 11 handles way heavier tasks smoothly.
Fixes That Work Without Setting Full-Screen Presentation
Here are three solutions I've tested successfully, none requiring you to switch to full-screen modal presentation:
- Delay Map View Initialization
Wait to add theMKMapViewuntil after the modal has finished appearing. This avoids conflicting with the presentation animation, and carries over smoothly to dismissal:
private var mapView: MKMapView? override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) guard mapView == nil else { return } let newMapView = MKMapView(frame: view.bounds) newMapView.autoresizingMask = [.flexibleWidth, .flexibleHeight] view.addSubview(newMapView) mapView = newMapView }
- Pause Map Rendering During Dismissal Animation
Hide the map view temporarily while the dismissal animation runs, then unhide it once the transition is complete. Using the transition coordinator makes this clean:
override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) guard let coordinator = transitionCoordinator, isBeingDismissed else { return } coordinator.animate(alongsideTransition: { _ in self.mapView.isHidden = true }, completion: { _ in self.mapView.isHidden = false }) }
- Disable Implicit Layer Animations for the Map
Turn off default layer animations on theMKMapViewto prevent clashes with the modal transition animation:
override func viewDidLoad() { super.viewDidLoad() mapView.layer.actions = [ "position": NSNull(), "bounds": NSNull(), "frame": NSNull() ] }
Why This Happens
From what I can tell, the issue stems from MKMapView's internal background rendering threads competing with the main thread's modal transition animation—especially when the modal isn't full-screen. The above fixes either avoid the conflict entirely or isolate the map's rendering during the transition.
内容的提问来源于stack exchange,提问作者Arda Oğul Üçpınar

