Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

ios - 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.

question from:https://stackoverflow.com/questions/65842954/set-root-view-controller-in-main-storyboard

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...