iOS how to uiview know appear and disappear?

Dmitry Nelepov picture Dmitry Nelepov · Apr 27, 2016 · Viewed 7.9k times · Source

In view on viewcontroller i can know when view on screen by viewDidAppear.

But in subclassed view from UIView can't know.

In android each view has methods didAttachToWindow and didDeattachFromWindow

So i can know when view appear and disappear from screen.

Is exists something like in iOS?

Answer

Bastian picture Bastian · Apr 27, 2016

you can overwrite the following functions in your view to find out what happened to your view:

removeFromSuperview when removed and as already mentioned willMoveToSuperview:/didMoveToSuperview: when added to a parent view.