mateiocristi
mateiocristi

Reputation: 5

set root view controller in main storyboard

main.storyboard

so i have this storyboard and i want the user to be shown the login view controller if he is not logged in or the tab view controller otherwise. this is my code inside the app delegate :

`

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:                                       [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()
    UITabBar.appearance().tintColor = .white
    
    // check user
    let authListener = Auth.auth().addStateDidChangeListener { auth, user in
        if user != nil {
            print("USER IS NOT NIL")
            userService.observeUserProfile(uid: user!.uid) { userProfile in
                userService.currentUserProfile = userProfile
            }
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "TabBarVC") as! UITabBarController
            self.window = UIWindow(frame: UIScreen.main.bounds)
            self.window?.rootViewController = vc
            self.window?.makeKeyAndVisible()
            
        } else {
            print("USER IS NIL")
            userService.currentUserProfile = nil
            let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let vc = storyboard.instantiateViewController(withIdentifier: "FirstVC") as! UIViewController
            vc.modalPresentationStyle = .fullScreen
            self.window = UIWindow(frame: UIScreen.main.bounds)
            self.window?.rootViewController = vc
            self.window?.makeKeyAndVisible()
        }
    }
}

` My problem is that if the user is not logged it looks like this:

the login screen

As you can see the view is not full screen even though i specified that in the app delegate so the user can simply dismiss it and enter the main screen. Also in the tab view controller i have the main screen with a playing video and the login screen also has a playing video in the background and both videos are played at the same time XD .Any tips would be welcome.

Upvotes: 0

Views: 1414

Answers (3)

Noman Umar
Noman Umar

Reputation: 409

    let nav = UINavigationController()
    nav.navigationBar.isHidden = true

    //your Controller 
    let first = Router.shared.splashVC()
    let third = Router.shared.CustomTabbarVC()

    third.selectedIndex = 0

    //add multiple controller in array 

    nav.viewControllers = [first,third]
    UIApplication.shared.keyWindow?.rootViewController = nav
    UIApplication.shared.keyWindow?.makeKeyAndVisible()

Upvotes: 1

Anand Khanpara
Anand Khanpara

Reputation: 862

First Select all ViewController and change presentation mode Automatic from Full Screen in Simulated Metrics.

Added UINavigationController in rootViewController

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "TabBarVC") as! UITabBarController
let navigationController = UINavigationController(rootViewController: vc)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = navigationController
vc.navigationController?.isNavigationBarHidden = true
self.window?.makeKeyAndVisible()

Upvotes: 0

henna patodiya
henna patodiya

Reputation: 36

change storyboard--> viewcontroller---> attribute inspector---> change presentation from Automatic to Full Screen

Upvotes: 1

Related Questions