How do I check if an UIViewController is currently being displayed?

前端 未结 7 608
臣服心动
臣服心动 2021-01-01 16:42

How do I check if an UIViewController is currently being displayed?

My UIViewControllers are listening for NSNotifications - e

相关标签:
7条回答
  • 2021-01-01 17:18

    Check to see if it's attached to the window. If it's not nil it's in hierarchy which is attached to the screen (of course it could be off the bounds of the screen, covered by some other view or have the hidden flag set)

    if (myViewController.view.window) {
      // I'm attached to the window
    } else {
      // not attached to the window
    }
    
    0 讨论(0)
提交回复
热议问题