Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Motion
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
Motion
Commits
aad47c6d
Unverified
Commit
aad47c6d
authored
Jun 28, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added first pass at Spring animmations
parent
a8b1aa0e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
281 deletions
+27
-281
Motion.xcodeproj/project.pbxproj
+4
-0
Sources/Extensions/Motion+CALayer.swift
+23
-17
Sources/MotionAnimation.swift
+0
-264
Sources/MotionCAAnimation.swift
+0
-0
No files found.
Motion.xcodeproj/project.pbxproj
View file @
aad47c6d
...
...
@@ -42,6 +42,7 @@
96AEB6AF1EE4610F009A3BE0
/* MatchPreprocessor.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB68B1EE4610F009A3BE0
/* MatchPreprocessor.swift */
;
};
96AEB6B01EE4610F009A3BE0
/* SourcePreprocessor.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96AEB68C1EE4610F009A3BE0
/* SourcePreprocessor.swift */
;
};
96E49A401EEA08F8006D5A93
/* MotionTransitionObserver.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96E49A3F1EEA08F8006D5A93
/* MotionTransitionObserver.swift */
;
};
96F8905B1F045099004BEB1A
/* MotionCAAnimation.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
96F8905A1F045099004BEB1A
/* MotionCAAnimation.swift */
;
};
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
...
...
@@ -83,6 +84,7 @@
96C98DE21E43809D00B22906
/* LICENSE */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
text
;
path
=
LICENSE
;
sourceTree
=
"<group>"
;
};
96C98DED1E438A5700B22906
/* Motion.h */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.c.h
;
path
=
Motion.h
;
sourceTree
=
"<group>"
;
};
96E49A3F1EEA08F8006D5A93
/* MotionTransitionObserver.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MotionTransitionObserver.swift
;
sourceTree
=
"<group>"
;
};
96F8905A1F045099004BEB1A
/* MotionCAAnimation.swift */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.swift
;
path
=
MotionCAAnimation.swift
;
sourceTree
=
"<group>"
;
};
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
...
...
@@ -173,6 +175,7 @@
96AEB67B1EE4610F009A3BE0
/* MotionTransition.swift */
,
96E49A3F1EEA08F8006D5A93
/* MotionTransitionObserver.swift */
,
96AEB67D1EE4610F009A3BE0
/* MotionPlugin.swift */
,
96F8905A1F045099004BEB1A
/* MotionCAAnimation.swift */
,
96AEB6641EE4610F009A3BE0
/* Animator */
,
96AEB66D1EE4610F009A3BE0
/* Extensions */
,
96AEB6861EE4610F009A3BE0
/* Preprocessors */
,
...
...
@@ -267,6 +270,7 @@
96AEB6931EE4610F009A3BE0
/* TransitionPreprocessor.swift in Sources */
,
96AEB68F1EE4610F009A3BE0
/* MotionDefaultAnimator.swift in Sources */
,
96AEB69D1EE4610F009A3BE0
/* Motion.swift in Sources */
,
96F8905B1F045099004BEB1A
/* MotionCAAnimation.swift in Sources */
,
963150D61EE51C7A002B0D42
/* MotionAnimation.swift in Sources */
,
968989DE1EE6633E003B8F3D
/* MotionAnimator.swift in Sources */
,
968989B91EE5B34B003B8F3D
/* MotionHasInsertOrder.swift in Sources */
,
...
...
Sources/Extensions/Motion+CALayer.swift
View file @
aad47c6d
...
...
@@ -160,102 +160,108 @@ fileprivate extension CALayer {
let
d
:
TimeInterval
=
targetState
.
duration
??
duration
if
let
v
=
targetState
.
backgroundColor
{
let
a
=
Motion
Basic
Animation
.
background
(
color
:
UIColor
(
cgColor
:
v
))
let
a
=
Motion
CA
Animation
.
background
(
color
:
UIColor
(
cgColor
:
v
))
a
.
fromValue
=
s
.
backgroundColor
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
borderColor
{
let
a
=
Motion
Basic
Animation
.
border
(
color
:
UIColor
(
cgColor
:
v
))
let
a
=
Motion
CA
Animation
.
border
(
color
:
UIColor
(
cgColor
:
v
))
a
.
fromValue
=
s
.
borderColor
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
borderWidth
{
let
a
=
Motion
Basic
Animation
.
border
(
width
:
v
)
let
a
=
Motion
CA
Animation
.
border
(
width
:
v
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
Double
(
s
.
borderWidth
))
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
cornerRadius
{
let
a
=
Motion
Basic
Animation
.
corner
(
radius
:
v
)
let
a
=
Motion
CA
Animation
.
corner
(
radius
:
v
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
Double
(
s
.
cornerRadius
))
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
transform
{
let
a
=
Motion
Basic
Animation
.
transform
(
v
)
let
a
=
Motion
CA
Animation
.
transform
(
v
)
a
.
fromValue
=
NSValue
(
caTransform3D
:
s
.
transform
)
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
spin
{
var
a
=
Motion
Basic
Animation
.
spinX
(
v
.
0
)
var
a
=
Motion
CA
Animation
.
spinX
(
v
.
0
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
0
)
anims
.
append
(
a
)
a
=
Motion
Basic
Animation
.
spinY
(
v
.
1
)
a
=
Motion
CA
Animation
.
spinY
(
v
.
1
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
0
)
anims
.
append
(
a
)
a
=
Motion
Basic
Animation
.
spinZ
(
v
.
2
)
a
=
Motion
CA
Animation
.
spinZ
(
v
.
2
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
0
)
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
position
{
let
a
=
Motion
Basic
Animation
.
position
(
v
)
let
a
=
Motion
CA
Animation
.
position
(
v
)
a
.
fromValue
=
NSValue
(
cgPoint
:
s
.
position
)
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
opacity
{
let
a
=
Motion
Basic
Animation
.
fade
(
v
)
let
a
=
Motion
CA
Animation
.
fade
(
v
)
a
.
fromValue
=
s
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
opacity
.
rawValue
)
??
NSNumber
(
floatLiteral
:
1
)
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
zPosition
{
let
a
=
Motion
Basic
Animation
.
zPosition
(
v
)
let
a
=
Motion
CA
Animation
.
zPosition
(
v
)
a
.
fromValue
=
s
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
zPosition
.
rawValue
)
??
NSNumber
(
floatLiteral
:
0
)
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
size
{
let
a
=
Motion
Basic
Animation
.
size
(
v
)
let
a
=
Motion
CA
Animation
.
size
(
v
)
a
.
fromValue
=
NSValue
(
cgSize
:
s
.
bounds
.
size
)
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
shadowPath
{
let
a
=
Motion
Basic
Animation
.
shadow
(
path
:
v
)
let
a
=
Motion
CA
Animation
.
shadow
(
path
:
v
)
a
.
fromValue
=
s
.
shadowPath
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
shadowColor
{
let
a
=
Motion
Basic
Animation
.
shadow
(
color
:
UIColor
(
cgColor
:
v
))
let
a
=
Motion
CA
Animation
.
shadow
(
color
:
UIColor
(
cgColor
:
v
))
a
.
fromValue
=
s
.
shadowColor
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
shadowOffset
{
let
a
=
Motion
Basic
Animation
.
shadow
(
offset
:
v
)
let
a
=
Motion
CA
Animation
.
shadow
(
offset
:
v
)
a
.
fromValue
=
NSValue
(
cgSize
:
s
.
shadowOffset
)
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
shadowOpacity
{
let
a
=
Motion
Basic
Animation
.
shadow
(
opacity
:
v
)
let
a
=
Motion
CA
Animation
.
shadow
(
opacity
:
v
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
Double
(
s
.
shadowOpacity
))
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
shadowRadius
{
let
a
=
Motion
Basic
Animation
.
shadow
(
radius
:
v
)
let
a
=
Motion
CA
Animation
.
shadow
(
radius
:
v
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
Double
(
s
.
shadowRadius
))
anims
.
append
(
a
)
}
if
#available(iOS 9.0, *)
,
let
(
stiffness
,
damping
)
=
targetState
.
spring
{
for
i
in
0
..<
anims
.
count
where
"cornerRadius"
!=
anims
[
i
]
.
keyPath
{
anims
[
i
]
=
MotionCAAnimation
.
convert
(
basic
:
anims
[
i
],
stiffness
:
stiffness
,
damping
:
damping
)
}
}
let
g
=
Motion
.
animate
(
group
:
anims
,
duration
:
d
)
g
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
...
...
Sources/MotionAnimation.swift
View file @
aad47c6d
...
...
@@ -447,267 +447,3 @@ extension MotionAnimation {
}
}
}
public
enum
MotionAnimationKeyPath
:
String
{
case
backgroundColor
case
barTintColor
case
borderColor
case
borderWidth
case
cornerRadius
case
transform
case
rotate
=
"transform.rotation"
case
rotateX
=
"transform.rotation.x"
case
rotateY
=
"transform.rotation.y"
case
rotateZ
=
"transform.rotation.z"
case
scale
=
"transform.scale"
case
scaleX
=
"transform.scale.x"
case
scaleY
=
"transform.scale.y"
case
scaleZ
=
"transform.scale.z"
case
translation
=
"transform.translation"
case
translationX
=
"transform.translation.x"
case
translationY
=
"transform.translation.y"
case
translationZ
=
"transform.translation.z"
case
position
case
opacity
case
zPosition
case
width
=
"bounds.size.width"
case
height
=
"bounds.size.height"
case
size
=
"bounds.size"
case
shadowPath
case
shadowColor
case
shadowOffset
case
shadowOpacity
case
shadowRadius
}
extension
CABasicAnimation
{
/**
A convenience initializer that takes a given MotionAnimationKeyPath.
- Parameter keyPath: An MotionAnimationKeyPath.
*/
public
convenience
init
(
keyPath
:
MotionAnimationKeyPath
)
{
self
.
init
(
keyPath
:
keyPath
.
rawValue
)
}
}
public
struct
MotionBasicAnimation
{
/**
Creates a CABasicAnimation for the backgroundColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
public
static
func
background
(
color
:
UIColor
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
backgroundColor
)
a
.
toValue
=
color
.
cgColor
return
a
}
/**
Creates a CABasicAnimation for the barTintColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
public
static
func
barTint
(
color
:
UIColor
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
barTintColor
)
a
.
toValue
=
color
.
cgColor
return
a
}
/**
Creates a CABasicAnimation for the borderColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
public
static
func
border
(
color
:
UIColor
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
borderColor
)
a
.
toValue
=
color
.
cgColor
return
a
}
/**
Creates a CABasicAnimation for the borderWidth key path.
- Parameter width: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
border
(
width
:
CGFloat
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
borderWidth
)
a
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
width
))
return
a
}
/**
Creates a CABasicAnimation for the cornerRadius key path.
- Parameter radius: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
corner
(
radius
:
CGFloat
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
cornerRadius
)
a
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
radius
))
return
a
}
/**
Creates a CABasicAnimation for the transform key path.
- Parameter _ t: A CATransform3D object.
- Returns: A CABasicAnimation.
*/
public
static
func
transform
(
_
t
:
CATransform3D
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
transform
)
a
.
toValue
=
NSValue
(
caTransform3D
:
t
)
return
a
}
/**
Creates a CABasicAnimation for the transform.rotate.x key path.
- Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
spinX
(
_
rotations
:
CGFloat
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
rotateX
)
a
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotations
))
return
a
}
/**
Creates a CABasicAnimation for the transform.rotate.y key path.
- Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
spinY
(
_
rotations
:
CGFloat
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
rotateY
)
a
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotations
))
return
a
}
/**
Creates a CABasicAnimation for the transform.rotate.z key path.
- Parameter _ rotations: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
spinZ
(
_
rotations
:
CGFloat
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
rotateZ
)
a
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotations
))
return
a
}
/**
Creates a CABasicAnimation for the position key path.
- Parameter _ point: A CGPoint.
- Returns: A CABasicAnimation.
*/
public
static
func
position
(
_
point
:
CGPoint
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
position
)
a
.
toValue
=
NSValue
(
cgPoint
:
point
)
return
a
}
/**
Creates a CABasicAnimation for the opacity key path.
- Parameter _ opacity: A Double.
- Returns: A CABasicAnimation.
*/
public
static
func
fade
(
_
opacity
:
Double
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
opacity
)
a
.
toValue
=
NSNumber
(
floatLiteral
:
opacity
)
return
a
}
/**
Creates a CABasicaAnimation for the zPosition key path.
- Parameter _ position: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
zPosition
(
_
position
:
CGFloat
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
zPosition
)
a
.
toValue
=
NSNumber
(
value
:
Double
(
position
))
return
a
}
/**
Creates a CABasicaAnimation for the width key path.
- Parameter width: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
width
(
_
width
:
CGFloat
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
width
)
a
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
width
))
return
a
}
/**
Creates a CABasicaAnimation for the height key path.
- Parameter height: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
height
(
_
height
:
CGFloat
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
height
)
a
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
height
))
return
a
}
/**
Creates a CABasicaAnimation for the height key path.
- Parameter size: A CGSize.
- Returns: A CABasicAnimation.
*/
public
static
func
size
(
_
size
:
CGSize
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
size
)
a
.
toValue
=
NSValue
(
cgSize
:
size
)
return
a
}
/**
Creates a CABasicAnimation for the shadowPath key path.
- Parameter path: A CGPath.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
path
:
CGPath
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowPath
)
animation
.
toValue
=
path
return
animation
}
/**
Creates a CABasicAnimation for the shadowColor key path.
- Parameter color: A UIColor.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
color
:
UIColor
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowColor
)
animation
.
toValue
=
color
.
cgColor
return
animation
}
/**
Creates a CABasicAnimation for the shadowOffset key path.
- Parameter offset: A CGSize.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
offset
:
CGSize
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowOffset
)
animation
.
toValue
=
NSValue
(
cgSize
:
offset
)
return
animation
}
/**
Creates a CABasicAnimation for the shadowOpacity key path.
- Parameter opacity: A Float.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
opacity
:
Float
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowOpacity
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
opacity
))
return
animation
}
/**
Creates a CABasicAnimation for the shadowRadius key path.
- Parameter radius: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
radius
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowRadius
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
radius
))
return
animation
}
}
Sources/MotionCAAnimation.swift
0 → 100644
View file @
aad47c6d
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment