在Xcode 11.2.1中打开后,弹出视图控制器立即关闭

时间:2019-12-04 06:55:02

标签: ios swift

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

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

但是它不起作用。

1 个答案:

答案 0 :(得分:0)

我已经在我的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)
}