我可以在WalkthroughView
个网页上添加UIViewController
,但我如何在appDelegate上添加WalkthroughView
?
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)
}
}
}
答案 0 :(得分: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
}
}
答案 1 :(得分:-1)
您可以使用此代理商
func application(_ application: UIApplication, didFinishLaunchingWithOptionslaunchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool