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
11 years ago
Commit
2e923b538bf54b01d2386f114214dc2496e21486
1 parent
9806c36a
setter methods for NSLayoutConstraint constant proxies like offset, centerOffset…
…, insets, sizeOffset.
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
144 additions
and
76 deletions
Examples/Masonry iOS Examples/MASExampleAnimatedView.m
Masonry/MASCompositeConstraint.m
Masonry/MASConstraint.h
Masonry/MASViewConstraint.m
Tests/Masonry Tests.xcodeproj/project.pbxproj
Examples/Masonry iOS Examples/MASExampleAnimatedView.m
View file @
2e923b5
...
...
@@ -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
:
^
{
...
...
Masonry/MASCompositeConstraint.m
View file @
2e923b5
...
...
@@ -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
{
...
...
Masonry/MASConstraint.h
View file @
2e923b5
...
...
@@ -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
;
...
...
Masonry/MASViewConstraint.m
View file @
2e923b5
...
...
@@ -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
.
layoutConstan
t
=
offset
;
self
.
offse
t
=
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
{
...
...
Tests/Masonry Tests.xcodeproj/project.pbxproj
View file @
2e923b5
...
...
@@ -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;
};
...
...
Please
register
or
login
to post a comment