-1

我可以WalkthroughViewUIViewController页面上添加,但如何WalkthroughView在 appDelegate 上添加?

 override open func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    let defaults = UserDefaults.standard
    let hasViewedWalkthrough = defaults.bool(forKey: "hasViewedWalkthrough")

    if !hasViewedWalkthrough {
       //
        print("succes")
        //
       if let pageVC = storyboard?.instantiateViewController(withIdentifier: "WalkthroughViewController") as? WalkthroughViewController {
           present(pageVC, animated: true, completion: nil)
        }
   }
}
4

2 回答 2

1

也许您的意思是其中一种选择?

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

        let rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "WalkthroughViewController")
        window = UIWindow(frame: UIScreen.main.bounds)

        window?.rootViewController = rootViewController
        window?.makeKeyAndVisible()

        return true
    }
}

或者:

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
            let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "WalkthroughViewController")
             window?.rootViewController?.present(viewController, animated: true, completion: nil)
        }

        return true
    }
}
于 2018-06-14T13:15:01.957 回答
-1

您可以为此使用应用程序委托

func application(_ application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
于 2018-06-14T12:08:45.900 回答