Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在appdelegate中关闭viewcontroller?_Ios_Swift_Viewcontroller_Appdelegate - Fatal编程技术网

Ios 如何在appdelegate中关闭viewcontroller?

Ios 如何在appdelegate中关闭viewcontroller?,ios,swift,viewcontroller,appdelegate,Ios,Swift,Viewcontroller,Appdelegate,我像这样创建暂停视图的启动屏幕 func applicationWillResignActive(_ application: UIApplication) { let storyboard = UIStoryboard(name: "Main", bundle: nil) let launchScreen = storyboard.instantiateViewController(withIdentifier: "launchScreen")

我像这样创建暂停视图的启动屏幕

func applicationWillResignActive(_ application: UIApplication) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let launchScreen = storyboard.instantiateViewController(withIdentifier: "launchScreen")
        launchScreen.restorationIdentifier = "launchScreen"

        var rootViewController = UIApplication.shared.keyWindow?.rootViewController
        while let presentController = rootViewController?.presentedViewController {
            rootViewController = presentController
        }
        rootViewController?.present(launchScreen, animated: false, completion: nil)
    }

func applicationDidEnterBackground(_ application: UIApplication) {

            guard let passcodeManageView = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "passcodeManageView") as? PasscodeManageViewController else { return }
            passcodeManageView.state = State.loginMode
            passcodeManageView.modalPresentationStyle = .overFullScreen

            var rootViewController = UIApplication.shared.keyWindow?.rootViewController
            while let presentController = rootViewController?.presentedViewController {
                rootViewController = presentController
            }
            rootViewController?.present(passcodeManageView, animated: false, completion: nil)

    }
但是,如何在ApplicationIdentinterBackground(:\)中取消启动屏幕

我如何找到特定的视图控制器以及根据

使用此方法释放共享资源,使计时器无效,并存储足够的应用程序状态信息,以便在应用程序稍后终止时将其恢复到当前状态您还应禁用应用程序用户界面的更新,并避免使用某些类型的共享系统资源(如用户的联系人数据库)。您还必须避免在后台使用OpenGL ES

你们不应该在应用程序进入后台后关闭启动屏幕。但如果您仍然想实现它,请使用
window?.rootViewController?
关闭,因为此时,
window?.rootViewController?
是启动屏幕

func applicationDidEnterBackground(_ application: UIApplication) {
  if (window?.rootViewController?.isKind(of: YOUR_LAUNCH_SCREEN_CLASS.self))! {
    window?.rootViewController?.dismiss(animated: true, completion: nil)
  }
}

使用此方法释放共享资源,使计时器无效,并存储足够的应用程序状态信息,以便在应用程序稍后终止时将其恢复到当前状态您还应禁用应用程序用户界面的更新,并避免使用某些类型的共享系统资源(如用户的联系人数据库)。您还必须避免在后台使用OpenGL ES

你们不应该在应用程序进入后台后关闭启动屏幕。但如果您仍然想实现它,请使用
window?.rootViewController?
关闭,因为此时,
window?.rootViewController?
是启动屏幕

func applicationDidEnterBackground(_ application: UIApplication) {
  if (window?.rootViewController?.isKind(of: YOUR_LAUNCH_SCREEN_CLASS.self))! {
    window?.rootViewController?.dismiss(animated: true, completion: nil)
  }
}

解决方案有问题吗?但是…我如何删除特定的视图控制器??因为在我的例子中,有时不应该消失的视图会消失。@allanWay,正如我所知,如果出现启动屏幕,您希望关闭它。所以只需要检查类的
rootViewController
。如果它有启动屏幕的类别,请将其关闭。您的答案在未进入后台之前工作正常。因为我创建了另一个viewcontroller应用程序,所以请输入背景。@allanWay您可以检查我的更新答案并告诉我它是否有效:)解决方案有问题吗?但是…我如何删除特定的view controller??因为在我的例子中,有时不应该消失的视图会消失。@allanWay,正如我所知,如果出现启动屏幕,您希望关闭它。所以只需要检查类的
rootViewController
。如果它有启动屏幕的类别,请将其关闭。您的答案在未进入后台之前工作正常。因为我创建了另一个viewcontroller应用程序,所以请输入背景。@allanWay您可以检查我的更新答案并告诉我它是否有效:)