iOS Present modal view controller on startup without flash

前端 未结 9 1154
囚心锁ツ
囚心锁ツ 2020-12-08 00:53

I\'d like to present modally, at first startup, a tutorial wizard to the user.

Is there a way to present a modal UIViewController on application startup

9条回答
  •  春和景丽
    2020-12-08 01:28

    let vc = UIViewController()
    vc.modalPresentationStyle = .custom
    vc.transitioningDelegate = noFlashTransitionDelegate
    present(vc, animated: false, completion: nil)
    
    class NoFlashTransitionDelegate: NSObject, UIViewControllerTransitioningDelegate {
    
        public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
            if source.view.window == nil,
                let overlayViewController = UIStoryboard(name: "LaunchScreen", bundle: nil).instantiateInitialViewController(),
                let overlay = overlayViewController.view {
                    source.view.addSubview(overlay)
                    UIView.animate(withDuration: 0, animations: {}) { (finished) in
                        overlay.removeFromSuperview()
                }
            }
            return nil
        }
    }
    

提交回复
热议问题