使用Swift在iOS中全局检测屏幕转换(切换)
我想知道是否有一种方法可以在应用程序中全局检测屏幕切换,例如从应用程序代理?我知道有一些方法,如isMovingFromParentViewController()和isMovingToParentViewController(),但这些方法只能在本地使用。任何信息都会有帮助,谢谢使用Swift在iOS中全局检测屏幕转换(切换),ios,swift,ios9,Ios,Swift,Ios9,我想知道是否有一种方法可以在应用程序中全局检测屏幕切换,例如从应用程序代理?我知道有一些方法,如isMovingFromParentViewController()和isMovingToParentViewController(),但这些方法只能在本地使用。任何信息都会有帮助,谢谢 Kristian如果您打算以以下方式使用全局UINavigationController作为AppDelegate中UIWindow的rootViewController let navigationControll
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
全局检测到它。你可以查看我的答案以了解更多信息嗨,你已经找到这个问题的解决方案了吗?