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

时间:2016-11-10 16:33:23

标签: ios swift ios9

我想知道是否有办法在应用中全局检测屏幕切换,例如来自Application Delegate?我知道有一些方法,如isMovingFromParentViewController()和isMovingToParentViewController(),但这些方法只能在本地使用。任何信息都会有所帮助,谢谢!

克里斯蒂安

1 个答案:

答案 0 :(得分:0)

如果您要通过以下方式使用全球UINavigationController作为rootViewController UIWindow的{​​{1}}。

AppDelegate

然后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相关的方法来观察这些变化。如果有帮助,请告诉我。

相关问题