Last Updated: February 25, 2016
·
1.056K
· solirvine

Filtering NSLayoutConstraints

This is a handy way to isolate an auto layout constraint in an iOS6+ app. Once you've got the constraint isolated, you can remove it, animate it, etc.

NSArray *constraints = [self.view constraints];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"constant = %f", 64.0];
NSArray *filteredArray = [constraints filteredArrayUsingPredicate:predicate];
NSLayoutConstraint *constraint =  [filteredArray objectAtIndex:0];

Other handy predicates for this filter are found in the NSLayoutConstraint docs