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
55b2fb8c4c51d469faa6d0abc8d392389138b047
1 parent
40c648b1
removing tap gesture from animation example
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
26 deletions
Masonry/MASCompositeConstraint.m
Masonry/MASConstraint.h
Masonry/MASViewConstraint.m
MasonryExamples/MasonryExamples/MASExampleAnimatedView.m
MasonryTests/MASCompositeConstraintSpec.m
Masonry/MASCompositeConstraint.m
View file @
55b2fb8
...
...
@@ -152,7 +152,7 @@
#pragma mark - layout relation
-
(
id
<
MASConstraint
>
(
^
)(
id
))
equality
WithBlock
:
(
id
<
MASConstraint
>
(
^
)(
id
<
MASConstraint
>
constraint
,
id
attr
))
block
{
-
(
id
<
MASConstraint
>
(
^
)(
id
))
relation
WithBlock
:
(
id
<
MASConstraint
>
(
^
)(
id
<
MASConstraint
>
constraint
,
id
attr
))
block
{
return
^
id
(
id
attr
)
{
if
(
!
self
.
added
)
{
[
self
.
delegate
addConstraint
:
self
];
...
...
@@ -170,19 +170,19 @@
}
-
(
id
<
MASConstraint
>
(
^
)(
id
))
equalTo
{
return
[
self
equality
WithBlock
:
^
id
(
id
<
MASConstraint
>
constraint
,
id
attr
)
{
return
[
self
relation
WithBlock
:
^
id
(
id
<
MASConstraint
>
constraint
,
id
attr
)
{
return
constraint
.
equalTo
(
attr
)
;
}];
}
-
(
id
<
MASConstraint
>
(
^
)(
id
))
greaterThanOrEqualTo
{
return
[
self
equality
WithBlock
:
^
id
<
MASConstraint
>
(
id
<
MASConstraint
>
constraint
,
id
attr
)
{
return
[
self
relation
WithBlock
:
^
id
<
MASConstraint
>
(
id
<
MASConstraint
>
constraint
,
id
attr
)
{
return
constraint
.
greaterThanOrEqualTo
(
attr
)
;
}];
}
-
(
id
<
MASConstraint
>
(
^
)(
id
))
lessThanOrEqualTo
{
return
[
self
equality
WithBlock
:
^
id
<
MASConstraint
>
(
id
<
MASConstraint
>
constraint
,
id
attr
)
{
return
[
self
relation
WithBlock
:
^
id
<
MASConstraint
>
(
id
<
MASConstraint
>
constraint
,
id
attr
)
{
return
constraint
.
lessThanOrEqualTo
(
attr
)
;
}];
}
...
...
Masonry/MASConstraint.h
View file @
55b2fb8
...
...
@@ -19,15 +19,22 @@ typedef float MASLayoutPriority;
@protocol
MASConstraint
<
NSObject
>
//layout constants
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
insets
)(
UIEdgeInsets
insets
);
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
sizeOffset
)(
CGSize
offset
);
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
centerOffset
)(
CGPoint
offset
);
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
offset
)(
CGFloat
offset
);
//layout multipliers
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
percent
)(
CGFloat
percent
);
//layout priority
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
priority
)(
UILayoutPriority
priority
);
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
priorityLow
)();
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
priorityMedium
)();
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
priorityHigh
)();
//layout relation
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
equalTo
)(
id
attr
);
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
greaterThanOrEqualTo
)(
id
attr
);
@property
(
nonatomic
,
copy
,
readonly
)
id
<
MASConstraint
>
(
^
lessThanOrEqualTo
)(
id
attr
);
...
...
Masonry/MASViewConstraint.m
View file @
55b2fb8
...
...
@@ -49,6 +49,21 @@
return
self
.
layoutConstraint
!=
nil
;
}
-
(
void
)
setSecondViewAttribute
:
(
id
)
secondViewAttribute
{
if
([
secondViewAttribute
isKindOfClass
:
NSNumber
.
class
])
{
self
.
layoutConstant
=
[
secondViewAttribute
doubleValue
];
// } else if ([secondViewAttribute isKindOfClass:NSArray.class]) {
// //TODO Composite
}
else
if
([
secondViewAttribute
isKindOfClass
:
UIView
.
class
])
{
_secondViewAttribute
=
[[
MASViewAttribute
alloc
]
initWithView
:
secondViewAttribute
layoutAttribute
:
self
.
firstViewAttribute
.
layoutAttribute
];
}
else
if
([
secondViewAttribute
isKindOfClass
:
MASViewAttribute
.
class
])
{
_secondViewAttribute
=
secondViewAttribute
;
}
else
{
NSAssert
(
YES
,
@"attempting to add unsupported attribute: %@"
,
secondViewAttribute
);
}
[
self
.
delegate
addConstraint
:
self
];
}
-
(
instancetype
)
cloneIfNeeded
{
if
(
self
.
hasLayoutRelation
)
{
MASViewAttribute
*
firstViewAttribute
=
[[
MASViewAttribute
alloc
]
initWithView
:
self
.
firstViewAttribute
.
view
layoutAttribute
:
self
.
firstViewAttribute
.
layoutAttribute
];
...
...
@@ -174,21 +189,6 @@
#pragma mark - layout relation
-
(
void
)
setSecondViewAttribute
:
(
id
)
secondViewAttribute
{
if
([
secondViewAttribute
isKindOfClass
:
NSNumber
.
class
])
{
self
.
layoutConstant
=
[
secondViewAttribute
doubleValue
];
}
else
if
([
secondViewAttribute
isKindOfClass
:
NSArray
.
class
])
{
//TODO Composite
}
else
if
([
secondViewAttribute
isKindOfClass
:
UIView
.
class
])
{
_secondViewAttribute
=
[[
MASViewAttribute
alloc
]
initWithView
:
secondViewAttribute
layoutAttribute
:
self
.
firstViewAttribute
.
layoutAttribute
];
}
else
if
([
secondViewAttribute
isKindOfClass
:
MASViewAttribute
.
class
])
{
_secondViewAttribute
=
secondViewAttribute
;
}
else
{
NSAssert
(
YES
,
@"attempting to add unsupported attribute: %@"
,
secondViewAttribute
);
}
[
self
.
delegate
addConstraint
:
self
];
}
-
(
id
<
MASConstraint
>
(
^
)(
id
))
equalTo
{
return
^
id
(
id
attr
)
{
NSAssert
(
!
self
.
hasBeenCommitted
,
...
...
MasonryExamples/MasonryExamples/MASExampleAnimatedView.m
View file @
55b2fb8
...
...
@@ -79,23 +79,35 @@
make
.
height
.
equalTo
(
view2
.
mas_height
)
;
}];
UITapGestureRecognizer
*
tapGestureRecognizer
=
[[
UITapGestureRecognizer
alloc
]
initWithTarget
:
self
action
:
@selector
(
didTapWithGestureRecognizer
:)];
[
self
addGestureRecognizer
:
tapGestureRecognizer
];
return
self
;
}
-
(
void
)
didTapWithGestureRecognizer
:
(
UITapGestureRecognizer
*
)
tapGestureRecognizer
{
self
.
padding
+=
20
;
UIEdgeInsets
paddingInsets
=
UIEdgeInsetsMake
(
self
.
padding
,
self
.
padding
,
self
.
padding
,
self
.
padding
);
-
(
void
)
didMoveToSuperview
{
[
self
startAnimatingWithInvertedInsets
:
NO
];
}
-
(
void
)
willMoveToSuperview
:
(
UIView
*
)
newSuperview
{
if
(
!
newSuperview
)
{
[
self
.
layer
removeAllAnimations
];
}
}
-
(
void
)
startAnimatingWithInvertedInsets
:
(
BOOL
)
invertedInsets
{
int
padding
=
invertedInsets
?
100
:
self
.
padding
;
UIEdgeInsets
paddingInsets
=
UIEdgeInsetsMake
(
padding
,
padding
,
padding
,
padding
);
for
(
id
<
MASConstraint
>
constraint
in
self
.
animatableConstraints
)
{
constraint
.
insets
(
paddingInsets
);
}
[
UIView
animateWithDuration
:
0
.
4
animations
:
^
{
[
UIView
animateWithDuration
:
1
animations
:
^
{
[
self
layoutIfNeeded
]
;
}
completion
:
^
(
BOOL
finished
)
{
if
(
finished
)
{
[
self
startAnimatingWithInvertedInsets
:
!
invertedInsets
]
;
}
}];
}
@end
...
...
MasonryTests/MASCompositeConstraintSpec.m
View file @
55b2fb8
...
...
@@ -83,6 +83,8 @@ it(@"should create width and height children", ^{
it
(
@"should complete children"
,
^
{
UIView
*
view
=
UIView
.
new
;
MASCompositeConstraint
*
composite
=
createCompositeWithType
(
MASCompositeViewConstraintTypeSize
);
//first equality statement
composite
.
equalTo
(
view
).
sizeOffset
(
CGSizeMake
(
90
,
30
));
[
verify
(
composite
.
delegate
)
addConstraint
:(
id
)
composite
];
...
...
@@ -100,6 +102,7 @@ it(@"should complete children", ^{
expect
(
viewConstraint
.
secondViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeHeight
);
expect
(
viewConstraint
.
layoutConstant
).
to
.
equal
(
30
);
//chain another equality statement
composite
.
greaterThanOrEqualTo
(
@6
);
expect
(
composite
.
completedChildConstraints
).
to
.
haveCountOf
(
4
);
expect
(
composite
.
currentChildConstraints
).
to
.
haveCountOf
(
2
);
...
...
@@ -113,6 +116,15 @@ it(@"should complete children", ^{
expect
(
viewConstraint
.
secondViewAttribute
.
view
).
to
.
beNil
();
expect
(
viewConstraint
.
secondViewAttribute
.
layoutAttribute
).
to
.
equal
(
0
);
expect
(
viewConstraint
.
layoutConstant
).
to
.
equal
(
6
);
//still referencing same view
viewConstraint
=
composite
.
currentChildConstraints
[
0
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
composite
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeWidth
);
viewConstraint
=
composite
.
currentChildConstraints
[
1
];
expect
(
viewConstraint
.
firstViewAttribute
.
view
).
to
.
beIdenticalTo
(
composite
.
view
);
expect
(
viewConstraint
.
firstViewAttribute
.
layoutAttribute
).
to
.
equal
(
NSLayoutAttributeHeight
);
});
SpecEnd
\ No newline at end of file
...
...
Please
register
or
login
to post a comment