Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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
使用Swift在iOS中全局检测屏幕转换(切换)_Ios_Swift_Ios9 - Fatal编程技术网

使用Swift在iOS中全局检测屏幕转换(切换)

使用Swift在iOS中全局检测屏幕转换(切换),ios,swift,ios9,Ios,Swift,Ios9,我想知道是否有一种方法可以在应用程序中全局检测屏幕切换,例如从应用程序代理?我知道有一些方法,如isMovingFromParentViewController()和isMovingToParentViewController(),但这些方法只能在本地使用。任何信息都会有帮助,谢谢 Kristian如果您打算以以下方式使用全局UINavigationController作为AppDelegate中UIWindow的rootViewController let navigationControll

我想知道是否有一种方法可以在应用程序中全局检测屏幕切换,例如从应用程序代理?我知道有一些方法,如isMovingFromParentViewController()和isMovingToParentViewController(),但这些方法只能在本地使用。任何信息都会有帮助,谢谢


Kristian

如果您打算以以下方式使用全局
UINavigationController
作为
AppDelegate
UIWindow
rootViewController

let navigationController:UINavigationController = UINavigationController(rootViewController: ViewController())
navigationController.delegate = self

window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
然后,
UINavigationControllerDelegate
中的以下委托方法将在
AppDelegate

func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {

}

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {

}

当新的
UIViewController
显示在
UINavigationController
中时,上述功能将帮助您。不幸的是,没有与
UIWindow
相关的方法来观察这些变化。请让我知道它是否有用。

您可以覆盖
视图将出现
视图显示
并从那里发布通知。您好,如果您将
UIViewController
用作应用程序中所有
UIViewController
容器视图
,则可以从
AppDelegate
全局检测到它。你可以查看我的答案以了解更多信息嗨,你已经找到这个问题的解决方案了吗?