Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ios
/
Masonry
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
Jonas Budelmann
12 years ago
Commit
cf2def3f6566162bc03d99845f7cf63a626d60a1
1 parent
5cd5b5c9
rename installation methods, set delegate in init of MASCompositeConstraint
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
25 deletions
Masonry/MASCompositeConstraint.h
Masonry/MASCompositeConstraint.m
Masonry/MASConstraint.h
Masonry/MASConstraintMaker.m
Masonry/MASViewConstraint.h
Masonry/MASViewConstraint.m
MasonryTests/MASCompositeConstraintSpec.m
MasonryTests/MASViewConstraintSpec.m
Masonry/MASCompositeConstraint.h
View file @
cf2def3
...
...
@@ -23,11 +23,6 @@ typedef NS_ENUM(NSInteger, MASCompositeConstraintType) {
@interface
MASCompositeConstraint
:
NSObject
<
MASConstraint
>
/**
* Usually MASConstraintMaker but could be a parent MASConstraint
*/
@property
(
nonatomic
,
weak
)
id
<
MASConstraintDelegate
>
delegate
;
/**
* default first item for any child MASConstraints
*/
@property
(
nonatomic
,
weak
,
readonly
)
UIView
*
view
;
...
...
Masonry/MASCompositeConstraint.m
View file @
cf2def3
...
...
@@ -19,6 +19,8 @@
@implementation
MASCompositeConstraint
@synthesize
delegate
=
_delegate
;
-
(
id
)
initWithView
:(
UIView
*
)
view
type
:(
MASCompositeConstraintType
)
type
{
self
=
[
super
init
];
if
(
!
self
)
return
nil
;
...
...
@@ -38,6 +40,9 @@
_type
=
MASCompositeConstraintTypeUnknown
;
_view
=
view
;
_childConstraints
=
[
children
mutableCopy
];
for
(
id
<
MASConstraint
>
constraint
in
_childConstraints
)
{
constraint
.
delegate
=
self
;
}
return
self
;
}
...
...
@@ -213,15 +218,15 @@
#pragma mark - MASConstraint
-
(
void
)
install
Constraint
{
-
(
void
)
install
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
[
constraint
install
Constraint
];
[
constraint
install
];
}
}
-
(
void
)
uninstall
Constraint
{
-
(
void
)
uninstall
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
childConstraints
)
{
[
constraint
uninstall
Constraint
];
[
constraint
uninstall
];
}
}
...
...
Masonry/MASConstraint.h
View file @
cf2def3
...
...
@@ -17,6 +17,8 @@ enum {
};
typedef
float
MASLayoutPriority
;
@protocol
MASConstraintDelegate
;
/**
* Enables Constraints to be created with chainable syntax
* Constraint can represent single NSLayoutConstraint (MASViewConstraint)
...
...
@@ -25,6 +27,11 @@ typedef float MASLayoutPriority;
@protocol
MASConstraint
<
NSObject
>
/**
* Usually MASConstraintMaker but could be a parent MASConstraint
*/
@property
(
nonatomic
,
weak
)
id
<
MASConstraintDelegate
>
delegate
;
/**
* Modifies the NSLayoutConstraint constant,
* only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
* NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
...
...
@@ -113,12 +120,12 @@ typedef float MASLayoutPriority;
/**
* Creates a NSLayoutConstraint. The constraint is installed to the first view or the or the closest common superview of the first and second view.
*/
-
(
void
)
install
Constraint
;
-
(
void
)
install
;
/**
* Removes previously installed NSLayoutConstraint
*/
-
(
void
)
uninstall
Constraint
;
-
(
void
)
uninstall
;
@end
...
...
Masonry/MASConstraintMaker.m
View file @
cf2def3
...
...
@@ -32,7 +32,7 @@
-
(
void
)
commit
{
for
(
id
<
MASConstraint
>
constraint
in
self
.
constraints
)
{
[
constraint
install
Constraint
];
[
constraint
install
];
}
[
self
.
constraints
removeAllObjects
];
}
...
...
Masonry/MASViewConstraint.h
View file @
cf2def3
...
...
@@ -13,11 +13,6 @@
@interface
MASViewConstraint
:
NSObject
<
MASConstraint
,
NSCopying
>
/**
* Usually MASConstraintMaker but could be a parent MASConstraint
*/
@property
(
nonatomic
,
weak
)
id
<
MASConstraintDelegate
>
delegate
;
/**
* First item/view and first attribute of the NSLayoutConstraint
*/
@property
(
nonatomic
,
strong
,
readonly
)
MASViewAttribute
*
firstViewAttribute
;
...
...
Masonry/MASViewConstraint.m
View file @
cf2def3
...
...
@@ -26,6 +26,8 @@
@implementation
MASViewConstraint
@synthesize
delegate
=
_delegate
;
-
(
id
)
initWithFirstViewAttribute
:(
MASViewAttribute
*
)
firstViewAttribute
{
self
=
[
super
init
];
if
(
!
self
)
return
nil
;
...
...
@@ -241,7 +243,7 @@
#pragma mark - MASConstraint
-
(
void
)
install
Constraint
{
-
(
void
)
install
{
NSAssert
(
!
self
.
hasBeenInstalled
,
@"Cannot install constraint more than once"
);
UIView
*
firstLayoutItem
=
self
.
firstViewAttribute
.
view
;
...
...
@@ -291,7 +293,7 @@
}
}
-
(
void
)
uninstall
Constraint
{
-
(
void
)
uninstall
{
[
self
.
installedView
removeConstraint
:
self
.
layoutConstraint
];
self
.
layoutConstraint
=
nil
;
self
.
installedView
=
nil
;
...
...
MasonryTests/MASCompositeConstraintSpec.m
View file @
cf2def3
...
...
@@ -125,7 +125,7 @@ it(@"should not remove on install", ^{
//first equality statement
composite
.
equalTo
(
newView
).
sizeOffset
(
CGSizeMake
(
90
,
30
));
[
composite
install
Constraint
];
[
composite
install
];
expect
(
composite
.
childConstraints
).
to
.
haveCountOf
(
2
);
});
...
...
MasonryTests/MASViewConstraintSpec.m
View file @
cf2def3
...
...
@@ -154,7 +154,7 @@ describe(@"create equality constraint", ^{
describe
(
@"multiplier & constant"
,
^
{
it
(
@"should not allow update of multiplier after layoutconstraint is created"
,
^
{
[
constraint
install
Constraint
];
[
constraint
install
];
expect
(
^
{
constraint
.
percent
(
0
.
9
);
...
...
@@ -162,7 +162,7 @@ describe(@"multiplier & constant", ^{
});
it
(
@"should allow update of constant after layoutconstraint is created"
,
^
{
[
constraint
install
Constraint
];
[
constraint
install
];
constraint
.
offset
(
10
);
expect
(
constraint
.
layoutConstant
).
to
.
equal
(
10
);
...
...
@@ -228,7 +228,7 @@ describe(@"install", ^{
constraint
.
percent
(
0
.
5
);
constraint
.
offset
(
10
);
constraint
.
priority
(
345
);
[
constraint
install
Constraint
];
[
constraint
install
];
expect
(
constraint
.
layoutConstraint
.
firstAttribute
).
to
.
equal
(
NSLayoutAttributeWidth
);
expect
(
constraint
.
layoutConstraint
.
secondAttribute
).
to
.
equal
(
NSLayoutAttributeHeight
);
...
...
@@ -245,12 +245,12 @@ describe(@"install", ^{
it
(
@"should uninstall constraint"
,
^
{
MASViewAttribute
*
secondViewAttribute
=
otherView
.
mas_height
;
constraint
.
equalTo
(
secondViewAttribute
);
[
constraint
install
Constraint
];
[
constraint
install
];
expect
(
superview
.
constraints
).
to
.
haveCountOf
(
1
);
expect
(
superview
.
constraints
[
0
]).
to
.
equal
(
constraint
.
layoutConstraint
);
[
constraint
uninstall
Constraint
];
[
constraint
uninstall
];
expect
(
superview
.
constraints
).
to
.
haveCountOf
(
0
);
});
...
...
Please
register
or
login
to post a comment