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

iPhone Plus机型上presentedView显示异常问题排查与解决

问题:iPhone Plus机型上自定义转场的presentedView无法填满屏幕

在iPhone 7模拟器中,我有一个名为cartView的视图,显示效果如下:
cartView显示截图

点击cartView底部的next按钮后,会弹出名为presentedView的视图,显示效果正常:
presentedView正常显示截图

触发弹出的代码

let vc = PresentedUserDetailsViewController() 
vc.modalPresentationStyle = .custom 
present(vc, animated: true, completion: nil) 

PresentedUserDetailsViewController核心实现

lazy var backdropView: UIView = { 
    let bdView = UIView(frame: self.view.bounds) 
    bdView.backgroundColor = UIColor.black.withAlphaComponent(0.5) 
    return bdView 
}() 

let menuHeight = UIScreen.main.bounds.height / 2

var isPresenting = false 

init() { 
    super.init(nibName: nil, bundle: nil) 
    modalPresentationStyle = .custom 
    transitioningDelegate = self 
} 

自定义转场动画扩展

extension PresentedUserDetailsViewController: UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning { 
    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
        return self 
    } 
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
        return self 
    } 
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 
        return 1 
    } 
    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 
        let containerView = transitionContext.containerView 
        let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) 
        guard let toVC = toViewController else { return } 
        isPresenting = !isPresenting 
        if isPresenting == true { 
            containerView.addSubview(toVC.view) 
            menuView.frame.origin.y += menuHeight 
            backdropView.alpha = 0 
            UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseOut], animations: { 
                self.menuView.frame.origin.y -= self.menuHeight 
                self.backdropView.alpha = 1 
            }, completion: { (finished) in 
                transitionContext.completeTransition(true) 
            }) 
        } else { 
            UIView.animate(withDuration: 0.4, delay: 0, options: [.curveEaseOut], animations: { 
                self.menuView.frame.origin.y += self.menuHeight 
                self.backdropView.alpha = 0 
            }, completion: { (finished) in 
                transitionContext.completeTransition(true) 
            }) 
        } 
    } 
} 

异常情况说明

但在iPhone Plus机型(如iPhone 6 Plus、iPhone 7 Plus)中运行时,presentedView显示异常:
iPhone Plus机型上presentedView异常显示截图

此时presentedView无法填满整个屏幕,且背后的cartView(包括next按钮)仍可见。

修改后的预期显示效果(iPhone 6 Plus):
修改后iPhone 6 Plus显示截图

iPad Air 2上的显示效果:
iPad Air 2上presentedView显示截图

请问如何让presentedView在iPhone Plus机型上像iPhone 7那样正常显示?


内容的提问来源于stack exchange,提问作者user8653398

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 06:42:24