iOS how to uiview know appear and disappear?
Asked Answered
Z

2

11

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?

Zirconia answered 27/4, 2016 at 10:44 Comment(0)
L
17

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.

Lefkowitz answered 27/4, 2016 at 15:40 Comment(0)
S
1

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.

Soneson answered 27/4, 2016 at 10:53 Comment(1)
This sends a notification when my view loaded. I want to get notified when my view removed from view. Any suggestions for that?Dalrymple

© 2022 - 2024 — McMap. All rights reserved.