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.
The view's window property is non-nil if a view is currently visible, so check the main view in the view controller: Invoking the view method causes the view to load (if it is not loaded) which is unnecessary and may be undesirable. It would be better to check first to see if it is already loaded.
They are separate classes: UIView is a class that represents the screen of the device of everything that is visible to the viewer, while UIViewController is a class that controls an instance of UIView, and handles all of the logic and code behind that view.
You can use willMoveToSuperview:
and didMoveToSuperview
to detect when the view is moved around. layoutSubviews
will be called when the superview changes frame.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With