UIView did appear?

后端 未结 5 1733
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 00:25

I\'m wondering, is there a way to get a delegate or something, when a particular UIView has been shown on the screen ?

相关标签:
5条回答
  • 2021-02-05 00:46

    Try these:

    – didAddSubview:
    – willRemoveSubview:
    – willMoveToSuperview:
    – didMoveToSuperview
    – willMoveToWindow:
    – didMoveToWindow
    - viewDidAppear:
    
    0 讨论(0)
  • 2021-02-05 00:56

    Another way to find out when a control is on screen is to subclass the View or Control and override drawRect...

    However, it's called when it's drawn and not only when first shown. So it's only sometimes what you want. It worked for my case. Make sure to call super as well! =)

    0 讨论(0)
  • 2021-02-05 01:06

    If you are managing the UIView via a UIViewController, then you can use the -viewDidAppear: method:

    - (void) viewDidAppear:(BOOL) animated {
       //do stuff...
       [super viewDidAppear:animated];
    }
    
    0 讨论(0)
  • 2021-02-05 01:07

    Swift version. Inside your UIView class just:

    override func willMove(toWindow newWindow: UIWindow?) {
        super.willMove(toWindow: newWindow)
    
        if newWindow == nil {
            // UIView disappear
        } else {
            // UIView appear
        }
    }
    
    0 讨论(0)
  • 2021-02-05 01:11

    If you manage your logic directly inside the UIView, use:

    - didMoveToSuperview
    

    If you manage your logic inside a UIViewController, use :

    - viewDidAppear:(BOOL)animated
    
    0 讨论(0)
提交回复
热议问题