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
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
56 deletions
+35
-56
Sources/Extensions/Motion+CALayer.swift
+23
-15
Sources/Extensions/Motion+CAMediaTimingFunction.swift
+2
-30
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,31 +133,29 @@ public extension CALayer {
- Parameter completion: An optional completion block.
*/
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
{
/**
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 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
)
Motion
.
delay
(
targetState
.
delay
)
{
[
weak
self
]
in
Motion
.
delay
(
targetState
.
delay
)
{
[
weak
self
,
targetState
=
targetState
,
completion
=
completion
]
in
guard
let
s
=
self
else
{
return
}
var
anims
=
[
CABasicAnimation
]()
let
tf
:
CAMediaTimingFunction
=
targetState
.
timingFunction
??
CAMediaTimingFunction
.
from
(
mediaTimingFunctionType
:
timingFunction
)
let
d
:
TimeInterval
=
targetState
.
duration
??
duration
var
d
=
targetState
.
duration
if
let
v
=
targetState
.
backgroundColor
{
let
a
=
MotionCAAnimation
.
background
(
color
:
UIColor
(
cgColor
:
v
))
...
...
@@ -258,23 +256,33 @@ fileprivate extension CALayer {
}
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
)
for
i
in
0
..<
anims
.
count
{
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
)
g
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
isRemovedOnCompletion
=
false
g
.
timingFunction
=
t
f
g
.
timingFunction
=
t
argetState
.
timingFunction
s
.
animate
(
g
)
guard
let
execute
=
completion
else
{
return
if
let
v
=
targetState
.
completion
{
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
...
...
@@ -55,37 +55,9 @@ public extension CAMediaTimingFunction {
// easing.net
static
let
easeOutBack
=
CAMediaTimingFunction
(
controlPoints
:
0.175
,
0.885
,
0.32
,
1.75
)
}
/**
Converts a string name matching a CAMediaTimingFunctionType to a
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
}
}
public
extension
CAMediaTimingFunction
{
/**
Converts a CAMediaTimingFunctionType to a CAMediaTimingFunction value.
- 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 {
public
var
delay
:
TimeInterval
=
0
/// The duration of the animation.
public
var
duration
:
TimeInterval
?
public
var
duration
:
TimeInterval
=
0.35
/// The timing function value of the animation.
public
var
timingFunction
:
CAMediaTimingFunction
?
/// The arc curve value.
public
var
arc
:
CGFloat
?
public
var
timingFunction
=
CAMediaTimingFunction
.
from
(
mediaTimingFunctionType
:
.
easeInOut
)
/// Custom target states.
public
var
custom
:
[
String
:
Any
]?
/// Completion block.
public
var
completion
:
(()
->
Void
)?
/**
An initializer that accepts an Array of MotionAnimations.
- Parameter animations: An Array of MotionAnimations.
...
...
Sources/MotionCAAnimation.swift
View file @
9174d3d6
...
...
@@ -90,17 +90,16 @@ fileprivate extension MotionCAAnimation {
internal
extension
MotionCAAnimation
{
/**
Converts a CABasicAnimation to a CASpringAnimation.
- Parameter
basic
: A CABasicAnimation.
- Parameter
animation
: A CABasicAnimation.
- Parameter stiffness: A CGFloat.
- Parameter damping: A CGFloat.
*/
static
func
convert
(
basic
:
CABasicAnimation
,
stiffness
:
CGFloat
,
damping
:
CGFloat
)
->
CASpringAnimation
{
let
a
=
CASpringAnimation
(
keyPath
:
basic
.
keyPath
)
a
.
fromValue
=
basic
.
fromValue
a
.
toValue
=
basic
.
toValue
static
func
convert
(
animation
:
CABasicAnimation
,
stiffness
:
CGFloat
,
damping
:
CGFloat
)
->
CASpringAnimation
{
let
a
=
CASpringAnimation
(
keyPath
:
animation
.
keyPath
)
a
.
fromValue
=
animation
.
fromValue
a
.
toValue
=
animation
.
toValue
a
.
stiffness
=
stiffness
a
.
damping
=
damping
a
.
duration
=
a
.
settlingDuration
*
0.9
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