|
@@ -67,6 +67,58 @@
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
+- (void)setLayoutConstantWithValue:(NSValue *)value {
|
|
|
+ if ([value isKindOfClass:NSNumber.class]) {
|
|
|
+ self.offset = [(NSNumber *)value doubleValue];
|
|
|
+ } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) {
|
|
|
+ CGPoint point;
|
|
|
+ [value getValue:&point];
|
|
|
+ self.centerOffset = point;
|
|
|
+ } else if (strcmp(value.objCType, @encode(CGSize)) == 0) {
|
|
|
+ CGSize size;
|
|
|
+ [value getValue:&size];
|
|
|
+ self.sizeOffset = size;
|
|
|
+ } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) {
|
|
|
+ MASEdgeInsets insets;
|
|
|
+ [value getValue:&insets];
|
|
|
+ self.insets = insets;
|
|
|
+ } else {
|
|
|
+ NSAssert(NO, @"attempting to set layout constant with unsupported value: %@", value);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (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;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
- (void)setLayoutRelation:(NSLayoutRelation)layoutRelation {
|
|
|
_layoutRelation = layoutRelation;
|
|
|
self.hasLayoutRelation = YES;
|
|
@@ -77,26 +129,8 @@
|
|
|
}
|
|
|
|
|
|
- (void)setSecondViewAttribute:(id)secondViewAttribute {
|
|
|
- if ([secondViewAttribute isKindOfClass:NSNumber.class]) {
|
|
|
- self.layoutConstant = [secondViewAttribute doubleValue];
|
|
|
- } else if ([secondViewAttribute isKindOfClass:NSValue.class]) {
|
|
|
- NSValue *value = (NSValue *)secondViewAttribute;
|
|
|
- if (strcmp(value.objCType, @encode(CGPoint)) == 0) {
|
|
|
- CGPoint point;
|
|
|
- [value getValue:&point];
|
|
|
- self.centerOffset = point;
|
|
|
- } else if (strcmp(value.objCType, @encode(CGSize)) == 0) {
|
|
|
- CGSize size;
|
|
|
- [value getValue:&size];
|
|
|
- self.sizeOffset = size;
|
|
|
- } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) {
|
|
|
- MASEdgeInsets insets;
|
|
|
- [value getValue:&insets];
|
|
|
- self.insets = insets;
|
|
|
- } else {
|
|
|
- // TODO: avoid duplication
|
|
|
- NSAssert(NO, @"attempting to add unsupported attribute: %@", secondViewAttribute);
|
|
|
- }
|
|
|
+ if ([secondViewAttribute isKindOfClass:NSValue.class]) {
|
|
|
+ [self setLayoutConstantWithValue:secondViewAttribute];
|
|
|
} else if ([secondViewAttribute isKindOfClass:MAS_VIEW.class]) {
|
|
|
_secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute];
|
|
|
} else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) {
|
|
@@ -106,36 +140,6 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#pragma mark - NSLayoutConstraint constant proxies
|
|
|
-
|
|
|
-- (MASConstraint * (^)(MASEdgeInsets))insets {
|
|
|
- return ^id(MASEdgeInsets insets){
|
|
|
- self.insets = insets;
|
|
|
- return self;
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-- (MASConstraint * (^)(CGSize))sizeOffset {
|
|
|
- return ^id(CGSize offset) {
|
|
|
- self.sizeOffset = offset;
|
|
|
- return self;
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-- (MASConstraint * (^)(CGPoint))centerOffset {
|
|
|
- return ^id(CGPoint offset) {
|
|
|
- self.centerOffset = offset;
|
|
|
- return self;
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-- (MASConstraint * (^)(CGFloat))offset {
|
|
|
- return ^id(CGFloat offset){
|
|
|
- self.offset = offset;
|
|
|
- return self;
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
#pragma mark - NSLayoutConstraint multiplier proxies
|
|
|
|
|
|
- (MASConstraint * (^)(CGFloat))multipliedBy {
|
|
@@ -159,7 +163,7 @@
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-#pragma mark - MASLayoutPriority proxies
|
|
|
+#pragma mark - MASLayoutPriority proxy
|
|
|
|
|
|
- (MASConstraint * (^)(MASLayoutPriority))priority {
|
|
|
return ^id(MASLayoutPriority priority) {
|
|
@@ -171,27 +175,6 @@
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-- (MASConstraint * (^)())priorityLow {
|
|
|
- return ^id{
|
|
|
- self.priority(MASLayoutPriorityDefaultLow);
|
|
|
- return self;
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-- (MASConstraint * (^)())priorityMedium {
|
|
|
- return ^id{
|
|
|
- self.priority(MASLayoutPriorityDefaultMedium);
|
|
|
- return self;
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-- (MASConstraint * (^)())priorityHigh {
|
|
|
- return ^id{
|
|
|
- self.priority(MASLayoutPriorityDefaultHigh);
|
|
|
- return self;
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
#pragma mark - NSLayoutRelation proxy
|
|
|
|
|
|
- (MASConstraint * (^)(id, NSLayoutRelation))_equalToWithRelation {
|
|
@@ -217,12 +200,6 @@
|
|
|
};
|
|
|
}
|
|
|
|
|
|
-#pragma mark - Semantic properties
|
|
|
-
|
|
|
-- (MASConstraint *)with {
|
|
|
- return self;
|
|
|
-}
|
|
|
-
|
|
|
#pragma mark - Animator proxy
|
|
|
|
|
|
#if TARGET_OS_MAC && !TARGET_OS_IPHONE
|
|
@@ -245,6 +222,10 @@
|
|
|
|
|
|
#pragma mark - NSLayoutConstraint constant setters
|
|
|
|
|
|
+- (void)setValueOffset:(id)offset {
|
|
|
+ [self setLayoutConstantWithValue:offset];
|
|
|
+}
|
|
|
+
|
|
|
- (void)setInsets:(MASEdgeInsets)insets {
|
|
|
NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
|
|
|
switch (layoutAttribute) {
|
|
@@ -265,38 +246,6 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-- (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 {
|