I have an OnboardingViewController which available to access from app's settings in a modal style.
When a user opens the app first time I want to show him the OnboardingVC in the same modal style (with an upper tabs effect, like so: Screenshot) as it loads if to present it from the Settings.
SceneDelegate setup:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: scene)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "OnboardingViewController") as! OnboardingViewController
window?.rootViewController = controller
window?.makeKeyAndVisible()
}
The problem it's always appear in a full screen, without the above modal tabs effect at the top.
How to solve it?
You can't present a
UIViewController(modally or fullscreen) which is window'srootViewController.To show Onboarding screen when user open app for the first time, set Home Screen/Login Screen (or any screen you want) as
rootViewControllerinSceneDelegate. Then from thatUIViewControlleryou can check if user open app for first time or not. Depending on that you can show the Onboarding screen.You must embed the
rootViewControllerin aUINavigationViewControllerto present/push anotherUIViewControllerIn SceneDelegate.swift modify the code like below.
Then in the Home screen (i assume it as HomeViewController) check the status of first opening and present Onboarding screen.
You can get the
rootViewControllerfrom anywhere in the app by using the code below. And then present any ViewController you want to show.