How to be notified when a UIView detached from its superView?

Jagie picture Jagie · Jun 19, 2010 · Viewed 13.5k times · Source

It seems that the UIView has not methods like "didRemoveFromSuperview" or "willRemoveFromSuperview".Then,How to listen to the event when a UIView removed from its superView?I should use KVO? thanks in advance!

Answer

likeToCode picture likeToCode · Feb 1, 2013

This topic is quite old, but I found a way to do it .Since google search wasn't helpful enough, here it is (taken from UIView's docs)

Observing View-Related Changes

– didAddSubview:

– willRemoveSubview:

– willMoveToSuperview:

– didMoveToSuperview

– willMoveToWindow:

– didMoveToWindow