首页 > 解决方案 > 弹出视图控制器在 Xcode 11.2.1 中打开后立即关闭

问题描述

通过使用以下方法调用弹出窗口

func annoucementdisplay()
{
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let ivc = storyboard.instantiateViewController(withIdentifier: "PopUpViewController") as! PopUpViewController
    ivc.modalTransitionStyle = .crossDissolve
    ivc.modalPresentationStyle = .custom
    let quiclvw = UIWindow(frame: UIScreen.main.bounds)
    quiclvw.windowLevel = UIWindow.Level.alert
    quiclvw.rootViewController = UIViewController()
    quiclvw.makeKeyAndVisible()
    let transition = CATransition()
    transition.duration = 1.0
    transition.type = CATransitionType.reveal
    transition.subtype = CATransitionSubtype.fromBottom
    quiclvw.layer.add(transition, forKey: kCATransition)
    quiclvw.rootViewController?.present(ivc, animated: true, completion: nil)
}

它在 Xcode 10.3 中运行良好,但是当我在 Xcode 11.2.1 中运行我的代码时,弹出窗口即将到来,但它在打开后立即消失。

我试过了

ivc.modalPresentationStyle = .fullScreen

但它不起作用。

标签: iosswift

解决方案


我已经在我的 xCode 11.2 上运行了这段代码,它运行成功。

func annoucementdisplay()
{
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let ivc = storyboard.instantiateViewController(withIdentifier: "PopUpViewController") as! PopUpViewController
    ivc.modalTransitionStyle = .crossDissolve
    ivc.modalPresentationStyle = .custom
    let quiclvw = UIWindow(frame: UIScreen.main.bounds)
    quiclvw.windowLevel = UIWindow.Level.alert
    quiclvw.rootViewController = UIViewController()
    quiclvw.makeKeyAndVisible()
    let transition = CATransition()
    transition.duration = 1.0
    transition.type = CATransitionType.reveal
    transition.subtype = CATransitionSubtype.fromBottom
    quiclvw.layer.add(transition, forKey: kCATransition)
    present(ivc, animated: true, completion: nil)
}

推荐阅读