Skip to content

Instantly share code, notes, and snippets.

@thornpig
Last active January 22, 2016 22:08
Show Gist options
  • Save thornpig/827ef418ab523fa8511d to your computer and use it in GitHub Desktop.
Save thornpig/827ef418ab523fa8511d to your computer and use it in GitHub Desktop.
Sequence of constraint activation/deactivation matters
-(void)updateConstraints
{
[super updateConstraints];
if (self.binaryFiles.count > 0)
{
//deactivate first, then activate, then change constant
[NSLayoutConstraint deactivateConstraints: @[self.attachmentButtonConstraintHeight]];
[NSLayoutConstraint activateConstraints: @[self.attachmentButtonConstraintAspectRatio]];
// self.attachmentButtonConstraintHeight.active = NO;
// self.attachmentButtonConstraintAspectRatio.active = YES;
}
else
{
[NSLayoutConstraint deactivateConstraints: @[self.attachmentButtonConstraintAspectRatio]];
[NSLayoutConstraint activateConstraints: @[self.attachmentButtonConstraintHeight]];
//changing constraint constant will trigger recalculation of layout and constraints conflict warnings if there are any.
self.attachmentButtonConstraintHeight.constant = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment