首页 > 解决方案 > 在主故事板中设置根视图控制器

问题描述

主故事板

所以我有这个故事板,如果用户未登录,我希望向用户显示登录视图控制器,否则显示标签视图控制器。这是我在应用程序委托中的代码:

`

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()
        }
    }
}

` 我的问题是,如果用户没有登录,它看起来像这样:

登录屏幕

如您所见,即使我在应用程序委托中指定了视图,视图也不是全屏的,因此用户可以简单地关闭它并进入主屏幕。同样在标签视图控制器中,我有一个播放视频的主屏幕,登录屏幕也有一个在后台播放的视频,两个视频同时播放 XD。欢迎提供任何提示。

标签: iosswiftxcode

解决方案


更改情节提要--> 视图控制器--> 属性检查器--> 将演示文稿从自动更改为全屏


推荐阅读