【问题标题】:Detecting screen transition (switching) globally in iOS with Swift使用 Swift 在 iOS 中全局检测屏幕转换(切换)
【发布时间】:2016-11-10 16:33:22
【问题描述】:

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

克里斯蒂安

【问题讨论】:

  • 您可以覆盖viewWillAppearviewDidAppear 并从那里发布通知。
  • 您好,如果您在应用程序中将UINavigationController 用作ContainerView,则可以从AppDelegate 全局检测到它。您可以查看我的答案以获取更多信息
  • 嗨,你已经找到解决这个问题的方法了吗?

标签: ios swift ios9


【解决方案1】:

如果您要使用全局UINavigationController 作为rootViewControllerUIWindowAppDelegate 中按以下方式。

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

}

UINavigationController 中出现新的UIViewController 时,上述功能将为您提供帮助。不幸的是,没有与UIWindow 相关的此类方法来观察这些变化。如果有帮助,请告诉我。

【讨论】:

    猜你喜欢
    • 2018-05-08
    • 2017-02-07
    • 2019-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-22
    • 2016-03-14
    • 2012-06-02
    相关资源
    最近更新 更多