【问题标题】:set root view controller in main storyboard在主故事板中设置根视图控制器
【发布时间】:2021-01-22 09:58:40
【问题描述】:

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

`

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。欢迎提供任何提示。

【问题讨论】:

  • 我可以立即发现的问题之一是您当前的用户检测逻辑是异步的,这意味着需要时间来完成......即使这不是您问题的根源,也绝对是您可能会考虑更改的内容。
  • 谢谢,我现在明白为什么我遇到了一些问题。我怎样才能让它同步?
  • 对此没有单一的“正确”答案,因为它取决于很多因素。一种常见的方法是尝试“自动登录”,显示某种形式的加载指示器,然后决定何时从身份验证服务获得响应。

标签: ios swift xcode


【解决方案1】:

更改故事板--> 视图控制器---> 属性检查器---> 将显示从自动更改为全屏

【讨论】:

    【解决方案2】:
        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()
    

    【讨论】:

      【解决方案3】:

      首先选择所有 ViewController 并在 Simulated Metrics 中从全屏自动更改演示模式。

      在 rootViewController 中添加 UINavigationController

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-18
        • 1970-01-01
        相关资源
        最近更新 更多