I have a UIView that contains multiple UIView subviews that has its own constraints. How do I remove the subviews' constraints?
//only removes the constraints on self.view
[self.view removeConstraints:self.view.constraints];
//I get warning: Incompatible pointer types sending 'NSArray *' to parameter of type 'NSLayoutConstraint'
[self.subview1 removeConstraints:self.subview1.constraints];
Try this code:
Basically, this iterates all of the constraints that are assigned to
self.view
and checks to see whetherself.subview1
is involved in the constraint. If so, that constraint gets pulled.You have to remove all the constraints of the view and its subview. So create an extension of UIView and then define the following method:
then call the following:
As answering later, This is in swift. This may help you.
I wrote an extension on UIView:
Interesting note is
secondItem
is an optional property ofNSLayoutConstraint
whilefirstItem
is non-optional. Why? Because sometimes you may need to constrain a view's height to a constant value, so you there is no other view involved.I took @Honey's answer and modified it to work so a view can remove the constraints in relation to his superview.