iOS: Detect when my UIView is add in other view

Jeremy Grenier picture Jeremy Grenier · Jul 19, 2012 · Viewed 13.6k times · Source
CustomView *customView = [...];
[self.view addSubview:customView];

I need to detect in my CustomView class when it is added in other views or when my superview changes.

Answer

Hampus Nilsson picture Hampus Nilsson · Jul 19, 2012

You can use willMoveToSuperview: and didMoveToSuperview to detect when the view is moved around. layoutSubviews will be called when the superview changes frame.