Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS how to uiview know appear and disappear?

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?

like image 744
Dmitry Nelepov Avatar asked Apr 27 '16 10:04

Dmitry Nelepov


2 Answers

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.

like image 133
Bastian Avatar answered Sep 17 '22 00:09

Bastian


I'm not sure about Android (what attaching/deattaching means), but on iOS you can override the willMoveToSuperview: / didMoveToSuperview: methods in your UIView subclass to receive a message in your UIView subclass. There's also willMoveToWindow: / didMoveToWindow: methods in UIView that you can override that will let you know in the UIView when the view has been added to a Window.

like image 21
James Bedford Avatar answered Sep 20 '22 00:09

James Bedford