renaming: sides to edges, constraints to constrain
Showing
11 changed files
with
65 additions
and
65 deletions
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | #import "MASConstraint.h" | 10 | #import "MASConstraint.h" |
11 | 11 | ||
12 | typedef NS_ENUM(NSInteger, MASCompositeViewConstraintType) { | 12 | typedef NS_ENUM(NSInteger, MASCompositeViewConstraintType) { |
13 | - MASCompositeViewConstraintTypeSides, | 13 | + MASCompositeViewConstraintTypeEdges, |
14 | MASCompositeViewConstraintTypeSize, | 14 | MASCompositeViewConstraintTypeSize, |
15 | MASCompositeViewConstraintTypeCenter, | 15 | MASCompositeViewConstraintTypeCenter, |
16 | }; | 16 | }; |
@@ -37,7 +37,7 @@ | @@ -37,7 +37,7 @@ | ||
37 | 37 | ||
38 | NSArray *viewAttributes; | 38 | NSArray *viewAttributes; |
39 | switch (self.type) { | 39 | switch (self.type) { |
40 | - case MASCompositeViewConstraintTypeSides: | 40 | + case MASCompositeViewConstraintTypeEdges: |
41 | viewAttributes = @[ | 41 | viewAttributes = @[ |
42 | self.view.mas_left, self.view.mas_top, | 42 | self.view.mas_left, self.view.mas_top, |
43 | self.view.mas_bottom, self.view.mas_right | 43 | self.view.mas_bottom, self.view.mas_right |
@@ -23,7 +23,7 @@ | @@ -23,7 +23,7 @@ | ||
23 | @property (nonatomic, strong, readonly) id<MASConstraint> centerY; | 23 | @property (nonatomic, strong, readonly) id<MASConstraint> centerY; |
24 | @property (nonatomic, strong, readonly) id<MASConstraint> baseline; | 24 | @property (nonatomic, strong, readonly) id<MASConstraint> baseline; |
25 | 25 | ||
26 | -@property (nonatomic, strong, readonly) id<MASConstraint> sides; | 26 | +@property (nonatomic, strong, readonly) id<MASConstraint> edges; |
27 | @property (nonatomic, strong, readonly) id<MASConstraint> size; | 27 | @property (nonatomic, strong, readonly) id<MASConstraint> size; |
28 | @property (nonatomic, strong, readonly) id<MASConstraint> center; | 28 | @property (nonatomic, strong, readonly) id<MASConstraint> center; |
29 | 29 |
@@ -101,8 +101,8 @@ | @@ -101,8 +101,8 @@ | ||
101 | 101 | ||
102 | #pragma mark - composite Attributes | 102 | #pragma mark - composite Attributes |
103 | 103 | ||
104 | -- (id<MASConstraint>)sides { | ||
105 | - MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithView:self.view type:MASCompositeViewConstraintTypeSides]; | 104 | +- (id<MASConstraint>)edges { |
105 | + MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithView:self.view type:MASCompositeViewConstraintTypeEdges]; | ||
106 | constraint.delegate = self; | 106 | constraint.delegate = self; |
107 | return constraint; | 107 | return constraint; |
108 | } | 108 | } |
@@ -24,6 +24,6 @@ | @@ -24,6 +24,6 @@ | ||
24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY; | 24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY; |
25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline; | 25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline; |
26 | 26 | ||
27 | -- (void)mas_buildConstraints:(void(^)(MASConstraintBuilder *constraints))block; | 27 | +- (void)mas_buildConstraints:(void(^)(MASConstraintBuilder *constrain))block; |
28 | 28 | ||
29 | @end | 29 | @end |
@@ -10,11 +10,11 @@ | @@ -10,11 +10,11 @@ | ||
10 | 10 | ||
11 | @implementation UIView (MASAdditions) | 11 | @implementation UIView (MASAdditions) |
12 | 12 | ||
13 | -- (void)mas_buildConstraints:(void(^)(MASConstraintBuilder *constraints))block { | 13 | +- (void)mas_buildConstraints:(void(^)(MASConstraintBuilder *))block { |
14 | self.translatesAutoresizingMaskIntoConstraints = NO; | 14 | self.translatesAutoresizingMaskIntoConstraints = NO; |
15 | - MASConstraintBuilder *viewConstraintBuilder = [[MASConstraintBuilder alloc] initWithView:self]; | ||
16 | - block(viewConstraintBuilder); | ||
17 | - [viewConstraintBuilder commit]; | 15 | + MASConstraintBuilder *constraintBuilder = [[MASConstraintBuilder alloc] initWithView:self]; |
16 | + block(constraintBuilder); | ||
17 | + [constraintBuilder commit]; | ||
18 | } | 18 | } |
19 | 19 | ||
20 | #pragma mark - attribute properties | 20 | #pragma mark - attribute properties |
@@ -48,7 +48,7 @@ MAS_ATTR_FORWARD(centerX); | @@ -48,7 +48,7 @@ MAS_ATTR_FORWARD(centerX); | ||
48 | MAS_ATTR_FORWARD(centerY); | 48 | MAS_ATTR_FORWARD(centerY); |
49 | MAS_ATTR_FORWARD(baseline); | 49 | MAS_ATTR_FORWARD(baseline); |
50 | 50 | ||
51 | -- (void)buildConstraints:(void(^)(MASConstraintBuilder *constraints))block { | 51 | +- (void)buildConstraints:(void(^)(MASConstraintBuilder *))block { |
52 | [self mas_buildConstraints:block]; | 52 | [self mas_buildConstraints:block]; |
53 | } | 53 | } |
54 | 54 |
@@ -45,38 +45,38 @@ | @@ -45,38 +45,38 @@ | ||
45 | 45 | ||
46 | self.animatableConstraints = NSMutableArray.new; | 46 | self.animatableConstraints = NSMutableArray.new; |
47 | 47 | ||
48 | - [view1 mas_buildConstraints:^(MASConstraintBuilder *constraints) { | 48 | + [view1 mas_buildConstraints:^(MASConstraintBuilder *constrain) { |
49 | [self.animatableConstraints addObjectsFromArray:@[ | 49 | [self.animatableConstraints addObjectsFromArray:@[ |
50 | - constraints.sides.equal(superview).insets(paddingInsets).priorityLow(), | ||
51 | - constraints.bottom.equal(view3.mas_top).offset(-padding), | ||
52 | - constraints.right.equal(view2.mas_left).offset(-padding), | ||
53 | - ]]; | 50 | + constrain.edges.equal(superview).insets(paddingInsets).priorityLow(), |
51 | + constrain.bottom.equal(view3.mas_top).offset(-padding), | ||
52 | + constrain.right.equal(view2.mas_left).offset(-padding), | ||
53 | + ]]; | ||
54 | 54 | ||
55 | - constraints.size.equal(view2); | ||
56 | - constraints.height.equal(view3.mas_height); | 55 | + constrain.size.equal(view2); |
56 | + constrain.height.equal(view3.mas_height); | ||
57 | }]; | 57 | }]; |
58 | 58 | ||
59 | - [view2 mas_buildConstraints:^(MASConstraintBuilder *constraints) { | 59 | + [view2 mas_buildConstraints:^(MASConstraintBuilder *constrain) { |
60 | [self.animatableConstraints addObjectsFromArray:@[ | 60 | [self.animatableConstraints addObjectsFromArray:@[ |
61 | - constraints.sides.equal(superview).insets(paddingInsets).priorityLow(), | ||
62 | - constraints.left.equal(view1.mas_right).offset(padding), | ||
63 | - constraints.bottom.equal(view3.mas_top).offset(-padding), | ||
64 | - ]]; | 61 | + constrain.edges.equal(superview).insets(paddingInsets).priorityLow(), |
62 | + constrain.left.equal(view1.mas_right).offset(padding), | ||
63 | + constrain.bottom.equal(view3.mas_top).offset(-padding), | ||
64 | + ]]; | ||
65 | 65 | ||
66 | - constraints.size.equal(view1); | ||
67 | - constraints.height.equal(view3.mas_height); | 66 | + constrain.size.equal(view1); |
67 | + constrain.height.equal(view3.mas_height); | ||
68 | }]; | 68 | }]; |
69 | 69 | ||
70 | - [view3 mas_buildConstraints:^(MASConstraintBuilder *constraints) { | 70 | + [view3 mas_buildConstraints:^(MASConstraintBuilder *constrain) { |
71 | [self.animatableConstraints addObjectsFromArray:@[ | 71 | [self.animatableConstraints addObjectsFromArray:@[ |
72 | - constraints.sides.equal(superview).insets(paddingInsets).priorityLow(), | ||
73 | - constraints.top.equal(view1.mas_bottom).offset(padding), | ||
74 | - ]]; | 72 | + constrain.edges.equal(superview).insets(paddingInsets).priorityLow(), |
73 | + constrain.top.equal(view1.mas_bottom).offset(padding), | ||
74 | + ]]; | ||
75 | 75 | ||
76 | //TODO or pass an array | 76 | //TODO or pass an array |
77 | //constraints.height.equal(superview.subviews); | 77 | //constraints.height.equal(superview.subviews); |
78 | - constraints.height.equal(view1.mas_height); | ||
79 | - constraints.height.equal(view2.mas_height); | 78 | + constrain.height.equal(view1.mas_height); |
79 | + constrain.height.equal(view2.mas_height); | ||
80 | }]; | 80 | }]; |
81 | 81 | ||
82 | UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapWithGestureRecognizer:)]; | 82 | UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapWithGestureRecognizer:)]; |
@@ -35,41 +35,41 @@ | @@ -35,41 +35,41 @@ | ||
35 | UIView *superview = self; | 35 | UIView *superview = self; |
36 | int padding = 10; | 36 | int padding = 10; |
37 | 37 | ||
38 | - [view1 mas_buildConstraints:^(MASConstraintBuilder *constraints) { | ||
39 | - constraints.top.equal(superview.mas_top).offset(padding); | ||
40 | - constraints.left.equal(superview.mas_left).offset(padding); | ||
41 | - constraints.bottom.equal(view3.mas_top).offset(-padding); | ||
42 | - constraints.right.equal(view2.mas_left).offset(-padding); | ||
43 | - constraints.width.equal(view2.mas_width); | 38 | + [view1 mas_buildConstraints:^(MASConstraintBuilder *constrain) { |
39 | + constrain.top.greaterThanOrEqual(superview.mas_top).offset(padding); | ||
40 | + constrain.left.equal(superview.mas_left).offset(padding); | ||
41 | + constrain.bottom.equal(view3.mas_top).offset(-padding); | ||
42 | + constrain.right.equal(view2.mas_left).offset(-padding); | ||
43 | + constrain.width.equal(view2.mas_width); | ||
44 | 44 | ||
45 | //you can chain same attribute | 45 | //you can chain same attribute |
46 | - constraints.height | 46 | + constrain.height |
47 | .equal(view2.mas_height) | 47 | .equal(view2.mas_height) |
48 | .equal(view3.mas_height); | 48 | .equal(view3.mas_height); |
49 | }]; | 49 | }]; |
50 | 50 | ||
51 | - [view2 mas_buildConstraints:^(MASConstraintBuilder *constraints) { | ||
52 | - constraints.top.equal(superview.mas_top).offset(padding); | ||
53 | - constraints.left.equal(view1.mas_right).offset(padding); | ||
54 | - constraints.bottom.equal(view3.mas_top).offset(-padding); | ||
55 | - constraints.right.equal(superview.mas_right).offset(-padding); | ||
56 | - constraints.width.equal(view1.mas_width); | 51 | + [view2 mas_buildConstraints:^(MASConstraintBuilder *constrain) { |
52 | + constrain.top.equal(superview.mas_top).offset(padding); | ||
53 | + constrain.left.equal(view1.mas_right).offset(padding); | ||
54 | + constrain.bottom.equal(view3.mas_top).offset(-padding); | ||
55 | + constrain.right.equal(superview.mas_right).offset(-padding); | ||
56 | + constrain.width.equal(view1.mas_width); | ||
57 | 57 | ||
58 | //or define it multiple times | 58 | //or define it multiple times |
59 | - constraints.height.equal(view1.mas_height); | ||
60 | - constraints.height.equal(view3.mas_height); | 59 | + constrain.height.equal(view1.mas_height); |
60 | + constrain.height.equal(view3.mas_height); | ||
61 | }]; | 61 | }]; |
62 | 62 | ||
63 | - [view3 mas_buildConstraints:^(MASConstraintBuilder *constraints) { | ||
64 | - constraints.top.equal(view1.mas_bottom).offset(padding); | ||
65 | - constraints.left.equal(superview.mas_left).offset(padding); | ||
66 | - constraints.bottom.equal(superview.mas_bottom).offset(-padding); | ||
67 | - constraints.right.equal(superview.mas_right).offset(-padding); | 63 | + [view3 mas_buildConstraints:^(MASConstraintBuilder *constrain) { |
64 | + constrain.top.equal(view1.mas_bottom).offset(padding); | ||
65 | + constrain.left.equal(superview.mas_left).offset(padding); | ||
66 | + constrain.bottom.equal(superview.mas_bottom).offset(-padding); | ||
67 | + constrain.right.equal(superview.mas_right).offset(-padding); | ||
68 | 68 | ||
69 | //TODO or pass an array | 69 | //TODO or pass an array |
70 | //constraints.height.equal(superview.subviews); | 70 | //constraints.height.equal(superview.subviews); |
71 | - constraints.height.equal(view1.mas_height); | ||
72 | - constraints.height.equal(view2.mas_height); | 71 | + constrain.height.equal(view1.mas_height); |
72 | + constrain.height.equal(view2.mas_height); | ||
73 | }]; | 73 | }]; |
74 | 74 | ||
75 | return self; | 75 | return self; |
@@ -28,18 +28,18 @@ | @@ -28,18 +28,18 @@ | ||
28 | 28 | ||
29 | //example of using constants | 29 | //example of using constants |
30 | 30 | ||
31 | - [view1 mas_buildConstraints:^(MASConstraintBuilder *constraints) { | ||
32 | - constraints.top.equal(@20); | ||
33 | - constraints.left.equal(@20); | ||
34 | - constraints.bottom.equal(@-20); | ||
35 | - constraints.right.equal(@-20); | 31 | + [view1 mas_buildConstraints:^(MASConstraintBuilder *constrain) { |
32 | + constrain.top.equal(@20); | ||
33 | + constrain.left.equal(@20); | ||
34 | + constrain.bottom.equal(@-20); | ||
35 | + constrain.right.equal(@-20); | ||
36 | }]; | 36 | }]; |
37 | 37 | ||
38 | - [view2 mas_buildConstraints:^(MASConstraintBuilder *constraints) { | ||
39 | - constraints.centerY.equal(@50); | ||
40 | - constraints.centerX.equal(@0); | ||
41 | - constraints.width.equal(@200); | ||
42 | - constraints.height.equal(@100); | 38 | + [view2 mas_buildConstraints:^(MASConstraintBuilder *constrain) { |
39 | + constrain.centerY.equal(@50); | ||
40 | + constrain.centerX.equal(@0); | ||
41 | + constrain.width.equal(@200); | ||
42 | + constrain.height.equal(@100); | ||
43 | }]; | 43 | }]; |
44 | 44 | ||
45 | return self; | 45 | return self; |
@@ -22,8 +22,8 @@ | @@ -22,8 +22,8 @@ | ||
22 | view.layer.borderWidth = 2; | 22 | view.layer.borderWidth = 2; |
23 | [self addSubview:view]; | 23 | [self addSubview:view]; |
24 | 24 | ||
25 | - [view mas_buildConstraints:^(MASConstraintBuilder *constraints) { | ||
26 | - constraints.sides.equal(lastView).insets(UIEdgeInsetsMake(5, 10, 15, 20)); | 25 | + [view mas_buildConstraints:^(MASConstraintBuilder *constrain) { |
26 | + constrain.edges.equal(lastView).insets(UIEdgeInsetsMake(5, 10, 15, 20)); | ||
27 | }]; | 27 | }]; |
28 | 28 | ||
29 | lastView = view; | 29 | lastView = view; |
-
Please register or login to post a comment