I\'m trying to animate a control in Cocoa with auto layout.
Now, I can set [[constraint animator] setConstant:newWidth];
, which works.
But how can I get the
Every contraint has an attribute [constraint firstAttribute]
It returns an enum NSLayoutAttribute
typedef NS_ENUM(NSInteger, NSLayoutAttribute) {
NSLayoutAttributeLeft = 1,
NSLayoutAttributeRight,
NSLayoutAttributeTop,
NSLayoutAttributeBottom,
NSLayoutAttributeLeading,
NSLayoutAttributeTrailing,
NSLayoutAttributeWidth,
NSLayoutAttributeHeight,
NSLayoutAttributeCenterX,
NSLayoutAttributeCenterY,
NSLayoutAttributeBaseline,
NSLayoutAttributeNotAnAttribute = 0
};
so you can check NSLayoutAttributeWidth for width.
Sample code:
NSArray constraints = [self constraints];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"firstAttribute = %d", NSLayoutAttributeWidth];
NSArray *filteredArray = [constraints filteredArrayUsingPredicate:predicate];
if(filteredArray.count == 0){
return nil;
}
NSLayoutConstraint *constraint = [constraints objectAtIndex:0];