You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

含MKMapView的模态视图交互式关闭时动画冻结问题求助

MKMapView Modal Interactive Dismissal Animation Freeze Fixes (No Full-Screen Required)

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 MKMapView via 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:

  1. Delay Map View Initialization
    Wait to add the MKMapView until 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
}
  1. 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
    })
}
  1. Disable Implicit Layer Animations for the Map
    Turn off default layer animations on the MKMapView to 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 11:12:35