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
9174d3d6
Unverified
Commit
9174d3d6
authored
Jun 28, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
completed initial MotionAnimation and MotionTransition
parent
aad47c6d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
60 deletions
+39
-60
Sources/Extensions/Motion+CALayer.swift
+23
-15
Sources/Extensions/Motion+CAMediaTimingFunction.swift
+6
-34
Sources/MotionAnimation.swift
+0
-0
Sources/MotionAnimationState.swift
+5
-5
Sources/MotionCAAnimation.swift
+5
-6
Sources/MotionTransition.swift
+0
-0
No files found.
Sources/Extensions/Motion+CALayer.swift
View file @
9174d3d6
...
@@ -133,32 +133,30 @@ public extension CALayer {
...
@@ -133,32 +133,30 @@ public extension CALayer {
- Parameter completion: An optional completion block.
- Parameter completion: An optional completion block.
*/
*/
func
animate
(
_
animations
:
[
MotionAnimation
],
completion
:
(()
->
Void
)?
=
nil
)
{
func
animate
(
_
animations
:
[
MotionAnimation
],
completion
:
(()
->
Void
)?
=
nil
)
{
animate
(
delay
:
0
,
duration
:
0.35
,
timingFunction
:
.
easeInOut
,
animations
:
animations
,
completion
:
completion
)
animate
(
animations
:
animations
,
completion
:
completion
)
}
}
}
}
fileprivate
extension
CALayer
{
fileprivate
extension
CALayer
{
/**
/**
A function that executes an Array of MotionAnimation values.
A function that executes an Array of MotionAnimation values.
- Parameter delay: The animation delay TimeInterval.
- Parameter duration: The animation duration TimeInterval.
- Parameter timingFunction: The animation CAMediaTimingFunctionType.
- Parameter animations: An Array of MotionAnimations.
- Parameter animations: An Array of MotionAnimations.
- Parameter completion: An optional completion block.
- Parameter completion: An optional completion block.
*/
*/
func
animate
(
delay
:
TimeInterval
,
duration
:
TimeInterval
,
timingFunction
:
CAMediaTimingFunctionType
,
animations
:
[
MotionAnimation
],
completion
:
(()
->
Void
)?
=
nil
)
{
func
animate
(
animations
:
[
MotionAnimation
],
completion
:
(()
->
Void
)?
=
nil
)
{
let
targetState
=
MotionAnimationState
(
animations
:
animations
)
let
targetState
=
MotionAnimationState
(
animations
:
animations
)
Motion
.
delay
(
targetState
.
delay
)
{
[
weak
self
]
in
Motion
.
delay
(
targetState
.
delay
)
{
[
weak
self
,
targetState
=
targetState
,
completion
=
completion
]
in
guard
let
s
=
self
else
{
guard
let
s
=
self
else
{
return
return
}
}
var
anims
=
[
CABasicAnimation
]()
var
anims
=
[
CABasicAnimation
]()
var
d
=
targetState
.
duration
let
tf
:
CAMediaTimingFunction
=
targetState
.
timingFunction
??
CAMediaTimingFunction
.
from
(
mediaTimingFunctionType
:
timingFunction
)
let
d
:
TimeInterval
=
targetState
.
duration
??
duration
if
let
v
=
targetState
.
backgroundColor
{
if
let
v
=
targetState
.
backgroundColor
{
let
a
=
MotionCAAnimation
.
background
(
color
:
UIColor
(
cgColor
:
v
))
let
a
=
MotionCAAnimation
.
background
(
color
:
UIColor
(
cgColor
:
v
))
a
.
fromValue
=
s
.
backgroundColor
a
.
fromValue
=
s
.
backgroundColor
...
@@ -258,23 +256,33 @@ fileprivate extension CALayer {
...
@@ -258,23 +256,33 @@ fileprivate extension CALayer {
}
}
if
#available(iOS 9.0, *)
,
let
(
stiffness
,
damping
)
=
targetState
.
spring
{
if
#available(iOS 9.0, *)
,
let
(
stiffness
,
damping
)
=
targetState
.
spring
{
for
i
in
0
..<
anims
.
count
where
"cornerRadius"
!=
anims
[
i
]
.
keyPath
{
for
i
in
0
..<
anims
.
count
{
anims
[
i
]
=
MotionCAAnimation
.
convert
(
basic
:
anims
[
i
],
stiffness
:
stiffness
,
damping
:
damping
)
let
v
=
anims
[
i
]
guard
"cornerRadius"
!=
v
.
keyPath
else
{
continue
}
let
a
=
MotionCAAnimation
.
convert
(
animation
:
v
,
stiffness
:
stiffness
,
damping
:
damping
)
anims
[
i
]
=
a
d
=
a
.
settlingDuration
*
0.9
}
}
}
}
let
g
=
Motion
.
animate
(
group
:
anims
,
duration
:
d
)
let
g
=
Motion
.
animate
(
group
:
anims
,
duration
:
d
)
g
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
isRemovedOnCompletion
=
false
g
.
isRemovedOnCompletion
=
false
g
.
timingFunction
=
t
f
g
.
timingFunction
=
t
argetState
.
timingFunction
s
.
animate
(
g
)
s
.
animate
(
g
)
guard
let
execute
=
completion
else
{
if
let
v
=
targetState
.
completion
{
return
Motion
.
delay
(
d
,
execute
:
v
)
}
}
Motion
.
delay
(
d
,
execute
:
execute
)
if
let
v
=
completion
{
Motion
.
delay
(
d
,
execute
:
v
)
}
}
}
}
}
}
}
Sources/Extensions/Motion+CAMediaTimingFunction.swift
View file @
9174d3d6
...
@@ -39,15 +39,15 @@ public enum CAMediaTimingFunctionType {
...
@@ -39,15 +39,15 @@ public enum CAMediaTimingFunctionType {
case
sharp
case
sharp
case
easeOutBack
case
easeOutBack
}
}
public
extension
CAMediaTimingFunction
{
public
extension
CAMediaTimingFunction
{
// default
// default
static
let
linear
=
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionLinear
)
static
let
linear
=
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionLinear
)
static
let
easeIn
=
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseIn
)
static
let
easeIn
=
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseIn
)
static
let
easeOut
=
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseOut
)
static
let
easeOut
=
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseOut
)
static
let
easeInOut
=
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseInEaseOut
)
static
let
easeInOut
=
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseInEaseOut
)
// material
// material
static
let
standard
=
CAMediaTimingFunction
(
controlPoints
:
0.4
,
0.0
,
0.2
,
1.0
)
static
let
standard
=
CAMediaTimingFunction
(
controlPoints
:
0.4
,
0.0
,
0.2
,
1.0
)
static
let
deceleration
=
CAMediaTimingFunction
(
controlPoints
:
0.0
,
0.0
,
0.2
,
1
)
static
let
deceleration
=
CAMediaTimingFunction
(
controlPoints
:
0.0
,
0.0
,
0.2
,
1
)
static
let
acceleration
=
CAMediaTimingFunction
(
controlPoints
:
0.4
,
0.0
,
1
,
1
)
static
let
acceleration
=
CAMediaTimingFunction
(
controlPoints
:
0.4
,
0.0
,
1
,
1
)
...
@@ -55,37 +55,9 @@ public extension CAMediaTimingFunction {
...
@@ -55,37 +55,9 @@ public extension CAMediaTimingFunction {
// easing.net
// easing.net
static
let
easeOutBack
=
CAMediaTimingFunction
(
controlPoints
:
0.175
,
0.885
,
0.32
,
1.75
)
static
let
easeOutBack
=
CAMediaTimingFunction
(
controlPoints
:
0.175
,
0.885
,
0.32
,
1.75
)
}
/**
Converts a string name matching a CAMediaTimingFunctionType to a
public
extension
CAMediaTimingFunction
{
CAMediaTimingFunction value.
- Parameter mediaTimingFunctionType: A String.
*/
static
func
from
(
mediaTimingFunctionType
:
String
)
->
CAMediaTimingFunction
?
{
switch
mediaTimingFunctionType
{
case
"linear"
:
return
.
linear
case
"easeIn"
:
return
.
easeIn
case
"easeOut"
:
return
.
easeOut
case
"easeInOut"
:
return
.
easeInOut
case
"standard"
:
return
.
standard
case
"deceleration"
:
return
.
deceleration
case
"acceleration"
:
return
.
acceleration
case
"sharp"
:
return
.
sharp
case
"easeOutBack"
:
return
.
easeOutBack
default
:
return
nil
}
}
/**
/**
Converts a CAMediaTimingFunctionType to a CAMediaTimingFunction value.
Converts a CAMediaTimingFunctionType to a CAMediaTimingFunction value.
- Parameter mediaTimingFunctionType: A CAMediaTimingFunctionType.
- Parameter mediaTimingFunctionType: A CAMediaTimingFunctionType.
...
...
Sources/MotionAnimation.swift
View file @
9174d3d6
This diff is collapsed.
Click to expand it.
Sources/MotionAnimationState.swift
View file @
9174d3d6
...
@@ -87,17 +87,17 @@ public struct MotionAnimationState {
...
@@ -87,17 +87,17 @@ public struct MotionAnimationState {
public
var
delay
:
TimeInterval
=
0
public
var
delay
:
TimeInterval
=
0
/// The duration of the animation.
/// The duration of the animation.
public
var
duration
:
TimeInterval
?
public
var
duration
:
TimeInterval
=
0.35
/// The timing function value of the animation.
/// The timing function value of the animation.
public
var
timingFunction
:
CAMediaTimingFunction
?
public
var
timingFunction
=
CAMediaTimingFunction
.
from
(
mediaTimingFunctionType
:
.
easeInOut
)
/// The arc curve value.
public
var
arc
:
CGFloat
?
/// Custom target states.
/// Custom target states.
public
var
custom
:
[
String
:
Any
]?
public
var
custom
:
[
String
:
Any
]?
/// Completion block.
public
var
completion
:
(()
->
Void
)?
/**
/**
An initializer that accepts an Array of MotionAnimations.
An initializer that accepts an Array of MotionAnimations.
- Parameter animations: An Array of MotionAnimations.
- Parameter animations: An Array of MotionAnimations.
...
...
Sources/MotionCAAnimation.swift
View file @
9174d3d6
...
@@ -90,17 +90,16 @@ fileprivate extension MotionCAAnimation {
...
@@ -90,17 +90,16 @@ fileprivate extension MotionCAAnimation {
internal
extension
MotionCAAnimation
{
internal
extension
MotionCAAnimation
{
/**
/**
Converts a CABasicAnimation to a CASpringAnimation.
Converts a CABasicAnimation to a CASpringAnimation.
- Parameter
basic
: A CABasicAnimation.
- Parameter
animation
: A CABasicAnimation.
- Parameter stiffness: A CGFloat.
- Parameter stiffness: A CGFloat.
- Parameter damping: A CGFloat.
- Parameter damping: A CGFloat.
*/
*/
static
func
convert
(
basic
:
CABasicAnimation
,
stiffness
:
CGFloat
,
damping
:
CGFloat
)
->
CASpringAnimation
{
static
func
convert
(
animation
:
CABasicAnimation
,
stiffness
:
CGFloat
,
damping
:
CGFloat
)
->
CASpringAnimation
{
let
a
=
CASpringAnimation
(
keyPath
:
basic
.
keyPath
)
let
a
=
CASpringAnimation
(
keyPath
:
animation
.
keyPath
)
a
.
fromValue
=
basic
.
fromValue
a
.
fromValue
=
animation
.
fromValue
a
.
toValue
=
basic
.
toValue
a
.
toValue
=
animation
.
toValue
a
.
stiffness
=
stiffness
a
.
stiffness
=
stiffness
a
.
damping
=
damping
a
.
damping
=
damping
a
.
duration
=
a
.
settlingDuration
*
0.9
return
a
return
a
}
}
}
}
...
...
Sources/MotionTransition.swift
View file @
9174d3d6
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