Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(De)activate multiple NSLayoutConstraints?

Tags:

ios

autolayout

I'm having an UIView with two subviews:

  • UIActivityIndicatorView
  • UIlabel

The UIView size is based on the UIActivityIndicatorView and UIlabel with NSLayoutConstraints.

At first the top of the UIView is linked to the top of the UIActivityIndicatorView, when I want to de-activate that constraint and activate the one with the top of the UIView linked to the top of the UIlabel I'm doing this:

_labelLayoutConstraintTopToSuperViewTop.active = YES;
_labelLayoutConstraintTopToActivityIndicatorViewBottom.active = NO;

This will result in an warning, but when I'm switching this to this:

_labelLayoutConstraintTopToActivityIndicatorViewBottom.active = NO;
_labelLayoutConstraintTopToSuperViewTop.active = YES;

I'm no longer getting the warning, until I link the top of the view to the UIActivityIndicatorView again.

Is there any way to put these changes in a batch or something? Am I misunderstanding something? I tried to use setNeedsUpdateConstraints, updateConstraintsIfNeeded, setNeedsLayout and layoutIfNeeded as well, all without success.

I hope I'm clear enough, thnx.

like image 721
Rick van der Linde Avatar asked May 01 '26 12:05

Rick van der Linde


1 Answers

F this, I can't figure it out.

As soon as I activate a constraint I get a warning about a constraint that I probably don't want, and that's correct, because I'm de-activating that constraint on the next line!

My fix for now is to just attach the top of the label to the top of the activity indicator and increase/decrease the constant as needed.

like image 96
Rick van der Linde Avatar answered May 03 '26 06:05

Rick van der Linde



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!