Authored by Jonas Budelmann

setter methods for NSLayoutConstraint constant proxies like offset, centerOffset…

…, insets, sizeOffset.
... ... @@ -98,7 +98,7 @@
int padding = invertedInsets ? 100 : self.padding;
UIEdgeInsets paddingInsets = UIEdgeInsetsMake(padding, padding, padding, padding);
for (id<MASConstraint> constraint in self.animatableConstraints) {
constraint.insets(paddingInsets);
constraint.insets = paddingInsets;
}
[UIView animateWithDuration:1 animations:^{
... ...
... ... @@ -44,36 +44,28 @@
- (id<MASConstraint> (^)(MASEdgeInsets))insets {
return ^id(MASEdgeInsets insets) {
for (id<MASConstraint> constraint in self.childConstraints) {
constraint.insets(insets);
}
self.insets = insets;
return self;
};
}
- (id<MASConstraint> (^)(CGFloat))offset {
return ^id(CGFloat offset) {
for (id<MASConstraint> constraint in self.childConstraints) {
constraint.offset(offset);
}
self.offset = offset;
return self;
};
}
- (id<MASConstraint> (^)(CGSize))sizeOffset {
return ^id(CGSize offset) {
for (id<MASConstraint> constraint in self.childConstraints) {
constraint.sizeOffset(offset);
}
self.sizeOffset = offset;
return self;
};
}
- (id<MASConstraint> (^)(CGPoint))centerOffset {
return ^id(CGPoint offset) {
for (id<MASConstraint> constraint in self.childConstraints) {
constraint.centerOffset(offset);
}
self.centerOffset = offset;
return self;
};
}
... ... @@ -191,6 +183,32 @@
};
}
#pragma mark - NSLayoutConstraint constant setters
- (void)setInsets:(UIEdgeInsets)insets {
for (id<MASConstraint> constraint in self.childConstraints) {
constraint.insets = insets;
}
}
- (void)setOffset:(CGFloat)offset {
for (id<MASConstraint> constraint in self.childConstraints) {
constraint.offset = offset;
}
}
- (void)setSizeOffset:(CGSize)sizeOffset {
for (id<MASConstraint> constraint in self.childConstraints) {
constraint.sizeOffset = sizeOffset;
}
}
- (void)setCenterOffset:(CGPoint)centerOffset {
for (id<MASConstraint> constraint in self.childConstraints) {
constraint.centerOffset = centerOffset;
}
}
#pragma mark - MASConstraint
- (void)install {
... ...
... ... @@ -17,67 +17,63 @@
*/
@protocol MASConstraint <NSObject>
/**
* Usually MASConstraintMaker but could be a parent MASConstraint
*/
@property (nonatomic, weak) id<MASConstraintDelegate> delegate;
// Chaining Support
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^insets)(MASEdgeInsets insets);
- (id<MASConstraint> (^)(MASEdgeInsets insets))insets;
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeWidth, NSLayoutAttributeHeight
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^sizeOffset)(CGSize offset);
- (id<MASConstraint> (^)(CGSize offset))sizeOffset;
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^centerOffset)(CGPoint offset);
- (id<MASConstraint> (^)(CGPoint offset))centerOffset;
/**
* Modifies the NSLayoutConstraint constant
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^offset)(CGFloat offset);
- (id<MASConstraint> (^)(CGFloat offset))offset;
/**
* Sets the NSLayoutConstraint multiplier property
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^multipliedBy)(CGFloat multiplier);
- (id<MASConstraint> (^)(CGFloat multiplier))multipliedBy;
/**
* Sets the NSLayoutConstraint multiplier to 1.0/dividedBy
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^dividedBy)(CGFloat divider);
- (id<MASConstraint> (^)(CGFloat divider))dividedBy;
/**
* Sets the NSLayoutConstraint priority to a float or MASLayoutPriority
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^priority)(MASLayoutPriority priority);
- (id<MASConstraint> (^)(MASLayoutPriority priority))priority;
/**
* Sets the NSLayoutConstraint priority to MASLayoutPriorityLow
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityLow)();
- (id<MASConstraint> (^)())priorityLow;
/**
* Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityMedium)();
- (id<MASConstraint> (^)())priorityMedium;
/**
* Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^priorityHigh)();
- (id<MASConstraint> (^)())priorityHigh;
/**
* Sets the constraint relation to NSLayoutRelationEqual
... ... @@ -85,7 +81,7 @@
* MASViewAttribute, UIView, NSNumber, NSArray
* see readme for more details.
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^equalTo)(id attr);
- (id<MASConstraint> (^)(id attr))equalTo;
/**
* Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual
... ... @@ -93,7 +89,7 @@
* MASViewAttribute, UIView, NSNumber, NSArray
* see readme for more details.
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^greaterThanOrEqualTo)(id attr);
- (id<MASConstraint> (^)(id attr))greaterThanOrEqualTo;
/**
* Sets the constraint relation to NSLayoutRelationLessThanOrEqual
... ... @@ -101,17 +97,50 @@
* MASViewAttribute, UIView, NSNumber, NSArray
* see readme for more details.
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^lessThanOrEqualTo)(id attr);
- (id<MASConstraint> (^)(id attr))lessThanOrEqualTo;
/**
* optional semantic property which has no effect but improves the readability of constraint
*/
@property (nonatomic, copy, readonly) id<MASConstraint> with;
- (id<MASConstraint>)with;
/**
* Sets the constraint debug name
*/
@property (nonatomic, copy, readonly) id<MASConstraint> (^key)(id key);
- (id<MASConstraint> (^)(id key))key;
// NSLayoutConstraint constant Setters
// for use outside of mas_updateConstraints/mas_makeConstraints blocks
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
*/
- (void)setInsets:(MASEdgeInsets)insets;
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeWidth, NSLayoutAttributeHeight
*/
- (void)setSizeOffset:(CGSize)sizeOffset;
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
*/
- (void)setCenterOffset:(CGPoint)centerOffset;
/**
* Modifies the NSLayoutConstraint constant
*/
- (void)setOffset:(CGFloat)offset;
// NSLayoutConstraint Installation support
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
/**
... ... @@ -126,7 +155,12 @@
@property (nonatomic, assign) BOOL updateExisting;
/**
* Creates a NSLayoutConstraint. The constraint is installed to the first view or the or the closest common superview of the first and second view.
* Usually MASConstraintMaker but could be a parent MASConstraint
*/
@property (nonatomic, weak) id<MASConstraintDelegate> delegate;
/**
* Creates a NSLayoutConstraint and adds it to the appropriate view.
*/
- (void)install;
... ...
... ... @@ -95,64 +95,28 @@
- (id<MASConstraint> (^)(MASEdgeInsets))insets {
return ^id(MASEdgeInsets insets){
NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
switch (layoutAttribute) {
case NSLayoutAttributeLeft:
self.layoutConstant = insets.left;
break;
case NSLayoutAttributeTop:
self.layoutConstant = insets.top;
break;
case NSLayoutAttributeBottom:
self.layoutConstant = -insets.bottom;
break;
case NSLayoutAttributeRight:
self.layoutConstant = -insets.right;
break;
default:
break;
}
self.insets = insets;
return self;
};
}
- (id<MASConstraint> (^)(CGSize))sizeOffset {
return ^id(CGSize offset) {
NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
switch (layoutAttribute) {
case NSLayoutAttributeWidth:
self.layoutConstant = offset.width;
break;
case NSLayoutAttributeHeight:
self.layoutConstant = offset.height;
break;
default:
break;
}
self.sizeOffset = offset;
return self;
};
}
- (id<MASConstraint> (^)(CGPoint))centerOffset {
return ^id(CGPoint offset) {
NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
switch (layoutAttribute) {
case NSLayoutAttributeCenterX:
self.layoutConstant = offset.x;
break;
case NSLayoutAttributeCenterY:
self.layoutConstant = offset.y;
break;
default:
break;
}
self.centerOffset = offset;
return self;
};
}
- (id<MASConstraint> (^)(CGFloat))offset {
return ^id(CGFloat offset){
self.layoutConstant = offset;
self.offset = offset;
return self;
};
}
... ... @@ -277,6 +241,60 @@
};
}
#pragma mark - NSLayoutConstraint constant setters
- (void)setInsets:(UIEdgeInsets)insets {
NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
switch (layoutAttribute) {
case NSLayoutAttributeLeft:
self.layoutConstant = insets.left;
break;
case NSLayoutAttributeTop:
self.layoutConstant = insets.top;
break;
case NSLayoutAttributeBottom:
self.layoutConstant = -insets.bottom;
break;
case NSLayoutAttributeRight:
self.layoutConstant = -insets.right;
break;
default:
break;
}
}
- (void)setOffset:(CGFloat)offset {
self.layoutConstant = offset;
}
- (void)setSizeOffset:(CGSize)sizeOffset {
NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
switch (layoutAttribute) {
case NSLayoutAttributeWidth:
self.layoutConstant = sizeOffset.width;
break;
case NSLayoutAttributeHeight:
self.layoutConstant = sizeOffset.height;
break;
default:
break;
}
}
- (void)setCenterOffset:(CGPoint)centerOffset {
NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
switch (layoutAttribute) {
case NSLayoutAttributeCenterX:
self.layoutConstant = centerOffset.x;
break;
case NSLayoutAttributeCenterY:
self.layoutConstant = centerOffset.y;
break;
default:
break;
}
}
#pragma mark - MASConstraint
- (void)install {
... ...
... ... @@ -28,7 +28,6 @@
DD717A5618442EC600FAA7A8 /* NSLayoutConstraint+MASDebugAdditionsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DD717A4E18442EC600FAA7A8 /* NSLayoutConstraint+MASDebugAdditionsSpec.m */; };
DD717A5718442EC600FAA7A8 /* View+MASAdditionsSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = DD717A5018442EC600FAA7A8 /* View+MASAdditionsSpec.m */; };
DD717A631844303200FAA7A8 /* GcovTestObserver.m in Sources */ = {isa = PBXBuildFile; fileRef = DD717A5F1844303200FAA7A8 /* GcovTestObserver.m */; };
DD717A641844303200FAA7A8 /* MasonryTests-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = DD717A601844303200FAA7A8 /* MasonryTests-Info.plist */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
... ... @@ -265,7 +264,6 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DD717A641844303200FAA7A8 /* MasonryTests-Info.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
... ...