How to programmatically remove a UIView

In the interface builder, the power of dimension classes allows you to set restrictions or remove them. In code, you can do something similar by switching the active property.

The Builder interface also allows you to set or remove views. However, I would like to do this programmatically. UIView has no active property. Is there any way I can uninstall a program programmatically? I am looking for something where I can just switch a boolean property, and the view and its restrictions go into quiescent state, and the view is no longer displayed, and its restrictions are no longer limited until it switches to be inactive, and then the view and restrictions work again.

Is it possible? Any workarounds?

+4
source share
1 answer

The view property hiddendoes not match the specified view. From the Apple documentation on Add or Remove Views for Size Class :

The runtime object for the uninstalled view is still being created. However, the view and any associated restrictions are not added to the view hierarchy and the view has the nil supervisor property. This is different from being hidden. The hidden view is in the hierarchy of views like any related constraints.

So this looks like the code equivalent:

//  "Uninstall" the view from the superview
[self.myView removeFromSuperView];

//  And add it back in
[self.view addSubview:self.myView]

, . , , ( ).

+1

All Articles