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
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
152 additions
and
163 deletions
+152
-163
Sources/Extensions/Motion+CALayer.swift
+23
-15
Sources/Extensions/Motion+CAMediaTimingFunction.swift
+6
-34
Sources/MotionAnimation.swift
+51
-50
Sources/MotionAnimationState.swift
+5
-5
Sources/MotionCAAnimation.swift
+5
-6
Sources/MotionTransition.swift
+62
-53
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
...
@@ -36,19 +36,19 @@ public class MotionAnimation {
...
@@ -36,19 +36,19 @@ public class MotionAnimation {
An initializer that accepts a given callback.
An initializer that accepts a given callback.
- Parameter applyFunction: A given callback.
- Parameter applyFunction: A given callback.
*/
*/
public
init
(
applyFunction
:
@escaping
(
inout
MotionAnimationState
)
->
Void
)
{
init
(
applyFunction
:
@escaping
(
inout
MotionAnimationState
)
->
Void
)
{
apply
=
applyFunction
apply
=
applyFunction
}
}
}
}
extension
MotionAnimation
{
public
extension
MotionAnimation
{
/**
/**
Animates the view's current background color to the
Animates the view's current background color to the
given color.
given color.
- Parameter color: A UIColor.
- Parameter color: A UIColor.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
background
(
color
:
UIColor
)
->
MotionAnimation
{
static
func
background
(
color
:
UIColor
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
backgroundColor
=
color
.
cgColor
$0
.
backgroundColor
=
color
.
cgColor
}
}
...
@@ -60,7 +60,7 @@ extension MotionAnimation {
...
@@ -60,7 +60,7 @@ extension MotionAnimation {
- Parameter color: A UIColor.
- Parameter color: A UIColor.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
border
(
color
:
UIColor
)
->
MotionAnimation
{
static
func
border
(
color
:
UIColor
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
borderColor
=
color
.
cgColor
$0
.
borderColor
=
color
.
cgColor
}
}
...
@@ -72,7 +72,7 @@ extension MotionAnimation {
...
@@ -72,7 +72,7 @@ extension MotionAnimation {
- Parameter width: A CGFloat.
- Parameter width: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
border
(
width
:
CGFloat
)
->
MotionAnimation
{
static
func
border
(
width
:
CGFloat
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
borderWidth
=
width
$0
.
borderWidth
=
width
}
}
...
@@ -84,7 +84,7 @@ extension MotionAnimation {
...
@@ -84,7 +84,7 @@ extension MotionAnimation {
- Parameter radius: A CGFloat.
- Parameter radius: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
corner
(
radius
:
CGFloat
)
->
MotionAnimation
{
static
func
corner
(
radius
:
CGFloat
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
cornerRadius
=
radius
$0
.
cornerRadius
=
radius
}
}
...
@@ -96,7 +96,7 @@ extension MotionAnimation {
...
@@ -96,7 +96,7 @@ extension MotionAnimation {
- Parameter _ transform: A CATransform3D.
- Parameter _ transform: A CATransform3D.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
transform
(
_
transform
:
CATransform3D
)
->
MotionAnimation
{
static
func
transform
(
_
transform
:
CATransform3D
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
transform
=
transform
$0
.
transform
=
transform
}
}
...
@@ -108,7 +108,7 @@ extension MotionAnimation {
...
@@ -108,7 +108,7 @@ extension MotionAnimation {
- Parameter _ perspective: A CGFloat.
- Parameter _ perspective: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
perspective
(
_
perspective
:
CGFloat
)
->
MotionAnimation
{
static
func
perspective
(
_
perspective
:
CGFloat
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
var
t
=
$0
.
transform
??
CATransform3DIdentity
var
t
=
$0
.
transform
??
CATransform3DIdentity
t
.
m34
=
1
/
-
perspective
t
.
m34
=
1
/
-
perspective
...
@@ -124,7 +124,7 @@ extension MotionAnimation {
...
@@ -124,7 +124,7 @@ extension MotionAnimation {
- Parameter z: A CGFloat.
- Parameter z: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
rotate
(
x
:
CGFloat
=
0
,
y
:
CGFloat
=
0
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
static
func
rotate
(
x
:
CGFloat
=
0
,
y
:
CGFloat
=
0
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
var
t
=
$0
.
transform
??
CATransform3DIdentity
var
t
=
$0
.
transform
??
CATransform3DIdentity
t
=
CATransform3DRotate
(
t
,
CGFloat
(
Double
.
pi
)
*
x
/
180
,
1
,
0
,
0
)
t
=
CATransform3DRotate
(
t
,
CGFloat
(
Double
.
pi
)
*
x
/
180
,
1
,
0
,
0
)
...
@@ -139,7 +139,7 @@ extension MotionAnimation {
...
@@ -139,7 +139,7 @@ extension MotionAnimation {
- Parameter z: A CGFloat, default is 0.
- Parameter z: A CGFloat, default is 0.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
rotate
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
static
func
rotate
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
return
.
rotate
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
return
.
rotate
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
}
}
...
@@ -148,7 +148,7 @@ extension MotionAnimation {
...
@@ -148,7 +148,7 @@ extension MotionAnimation {
- Parameter _ z: A CGFloat.
- Parameter _ z: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
rotate
(
_
z
:
CGFloat
)
->
MotionAnimation
{
static
func
rotate
(
_
z
:
CGFloat
)
->
MotionAnimation
{
return
.
rotate
(
z
:
z
)
return
.
rotate
(
z
:
z
)
}
}
...
@@ -160,7 +160,7 @@ extension MotionAnimation {
...
@@ -160,7 +160,7 @@ extension MotionAnimation {
- Parameter z: A CGFloat.
- Parameter z: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
spin
(
x
:
CGFloat
=
0
,
y
:
CGFloat
=
0
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
static
func
spin
(
x
:
CGFloat
=
0
,
y
:
CGFloat
=
0
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
spin
=
(
x
,
y
,
z
)
$0
.
spin
=
(
x
,
y
,
z
)
}
}
...
@@ -172,7 +172,7 @@ extension MotionAnimation {
...
@@ -172,7 +172,7 @@ extension MotionAnimation {
- Parameter z: A CGFloat, default is 0.
- Parameter z: A CGFloat, default is 0.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
spin
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
static
func
spin
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
return
.
spin
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
return
.
spin
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
}
}
...
@@ -181,7 +181,7 @@ extension MotionAnimation {
...
@@ -181,7 +181,7 @@ extension MotionAnimation {
- Parameter _ z: A CGFloat.
- Parameter _ z: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
spin
(
_
z
:
CGFloat
)
->
MotionAnimation
{
static
func
spin
(
_
z
:
CGFloat
)
->
MotionAnimation
{
return
.
spin
(
z
:
z
)
return
.
spin
(
z
:
z
)
}
}
...
@@ -192,7 +192,7 @@ extension MotionAnimation {
...
@@ -192,7 +192,7 @@ extension MotionAnimation {
- Parameter z: A CGFloat.
- Parameter z: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
scale
(
x
:
CGFloat
=
1
,
y
:
CGFloat
=
1
,
z
:
CGFloat
=
1
)
->
MotionAnimation
{
static
func
scale
(
x
:
CGFloat
=
1
,
y
:
CGFloat
=
1
,
z
:
CGFloat
=
1
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
transform
=
CATransform3DScale
(
$0
.
transform
??
CATransform3DIdentity
,
x
,
y
,
z
)
$0
.
transform
=
CATransform3DScale
(
$0
.
transform
??
CATransform3DIdentity
,
x
,
y
,
z
)
}
}
...
@@ -203,7 +203,7 @@ extension MotionAnimation {
...
@@ -203,7 +203,7 @@ extension MotionAnimation {
- Parameter _ xy: A CGFloat.
- Parameter _ xy: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
scale
(
_
xy
:
CGFloat
)
->
MotionAnimation
{
static
func
scale
(
_
xy
:
CGFloat
)
->
MotionAnimation
{
return
.
scale
(
x
:
xy
,
y
:
xy
)
return
.
scale
(
x
:
xy
,
y
:
xy
)
}
}
...
@@ -215,7 +215,7 @@ extension MotionAnimation {
...
@@ -215,7 +215,7 @@ extension MotionAnimation {
- Parameter z: A CGFloat.
- Parameter z: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
translate
(
x
:
CGFloat
=
0
,
y
:
CGFloat
=
0
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
static
func
translate
(
x
:
CGFloat
=
0
,
y
:
CGFloat
=
0
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
transform
=
CATransform3DTranslate
(
$0
.
transform
??
CATransform3DIdentity
,
x
,
y
,
z
)
$0
.
transform
=
CATransform3DTranslate
(
$0
.
transform
??
CATransform3DIdentity
,
x
,
y
,
z
)
}
}
...
@@ -228,7 +228,7 @@ extension MotionAnimation {
...
@@ -228,7 +228,7 @@ extension MotionAnimation {
- Parameter z: A CGFloat, default is 0.
- Parameter z: A CGFloat, default is 0.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
translate
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
static
func
translate
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
return
.
translate
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
return
.
translate
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
}
}
...
@@ -237,24 +237,24 @@ extension MotionAnimation {
...
@@ -237,24 +237,24 @@ extension MotionAnimation {
- Parameter _ point: A CGPoint.
- Parameter _ point: A CGPoint.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
position
(
_
point
:
CGPoint
)
->
MotionAnimation
{
static
func
position
(
_
point
:
CGPoint
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
position
=
point
$0
.
position
=
point
}
}
}
}
/// Fades the view in during an animation.
/// Fades the view in during an animation.
public
static
var
fadeIn
=
MotionAnimation
.
fade
(
1
)
static
var
fadeIn
=
MotionAnimation
.
fade
(
1
)
/// Fades the view out during an animation.
/// Fades the view out during an animation.
public
static
var
fadeOut
=
MotionAnimation
.
fade
(
0
)
static
var
fadeOut
=
MotionAnimation
.
fade
(
0
)
/**
/**
Animates the view's current opacity to the given one.
Animates the view's current opacity to the given one.
- Parameter _ opacity: A Double.
- Parameter _ opacity: A Double.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
fade
(
_
opacity
:
Double
)
->
MotionAnimation
{
static
func
fade
(
_
opacity
:
Double
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
opacity
=
opacity
$0
.
opacity
=
opacity
}
}
...
@@ -265,7 +265,7 @@ extension MotionAnimation {
...
@@ -265,7 +265,7 @@ extension MotionAnimation {
- Parameter _ position: An Int.
- Parameter _ position: An Int.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
zPosition
(
_
position
:
CGFloat
)
->
MotionAnimation
{
static
func
zPosition
(
_
position
:
CGFloat
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
zPosition
=
position
$0
.
zPosition
=
position
}
}
...
@@ -276,7 +276,7 @@ extension MotionAnimation {
...
@@ -276,7 +276,7 @@ extension MotionAnimation {
- Parameter _ size: A CGSize.
- Parameter _ size: A CGSize.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
size
(
_
size
:
CGSize
)
->
MotionAnimation
{
static
func
size
(
_
size
:
CGSize
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
size
=
size
$0
.
size
=
size
}
}
...
@@ -287,7 +287,7 @@ extension MotionAnimation {
...
@@ -287,7 +287,7 @@ extension MotionAnimation {
- Parameter path: A CGPath.
- Parameter path: A CGPath.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
shadow
(
path
:
CGPath
)
->
MotionAnimation
{
static
func
shadow
(
path
:
CGPath
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
shadowPath
=
path
$0
.
shadowPath
=
path
}
}
...
@@ -298,7 +298,7 @@ extension MotionAnimation {
...
@@ -298,7 +298,7 @@ extension MotionAnimation {
- Parameter color: A UIColor.
- Parameter color: A UIColor.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
shadow
(
color
:
UIColor
)
->
MotionAnimation
{
static
func
shadow
(
color
:
UIColor
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
shadowColor
=
color
.
cgColor
$0
.
shadowColor
=
color
.
cgColor
}
}
...
@@ -309,7 +309,7 @@ extension MotionAnimation {
...
@@ -309,7 +309,7 @@ extension MotionAnimation {
- Parameter offset: A CGSize.
- Parameter offset: A CGSize.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
shadow
(
offset
:
CGSize
)
->
MotionAnimation
{
static
func
shadow
(
offset
:
CGSize
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
shadowOffset
=
offset
$0
.
shadowOffset
=
offset
}
}
...
@@ -320,7 +320,7 @@ extension MotionAnimation {
...
@@ -320,7 +320,7 @@ extension MotionAnimation {
- Parameter opacity: A Float.
- Parameter opacity: A Float.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
shadow
(
opacity
:
Float
)
->
MotionAnimation
{
static
func
shadow
(
opacity
:
Float
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
shadowOpacity
=
opacity
$0
.
shadowOpacity
=
opacity
}
}
...
@@ -331,7 +331,7 @@ extension MotionAnimation {
...
@@ -331,7 +331,7 @@ extension MotionAnimation {
- Parameter radius: A CGFloat.
- Parameter radius: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
shadow
(
radius
:
CGFloat
)
->
MotionAnimation
{
static
func
shadow
(
radius
:
CGFloat
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
shadowRadius
=
radius
$0
.
shadowRadius
=
radius
}
}
...
@@ -343,7 +343,7 @@ extension MotionAnimation {
...
@@ -343,7 +343,7 @@ extension MotionAnimation {
- Parameter opacity: A Float.
- Parameter opacity: A Float.
- Parameter radius: A CGFloat.
- Parameter radius: A CGFloat.
*/
*/
public
static
func
depth
(
offset
:
CGSize
,
opacity
:
Float
,
radius
:
CGFloat
)
->
MotionAnimation
{
static
func
depth
(
offset
:
CGSize
,
opacity
:
Float
,
radius
:
CGFloat
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
shadowOffset
=
offset
$0
.
shadowOffset
=
offset
$0
.
shadowOpacity
=
opacity
$0
.
shadowOpacity
=
opacity
...
@@ -355,7 +355,7 @@ extension MotionAnimation {
...
@@ -355,7 +355,7 @@ extension MotionAnimation {
Animates the views shadow offset, opacity, and radius.
Animates the views shadow offset, opacity, and radius.
- Parameter _ depth: A tuple (CGSize, FLoat, CGFloat).
- Parameter _ depth: A tuple (CGSize, FLoat, CGFloat).
*/
*/
public
static
func
depth
(
_
depth
:
(
CGSize
,
Float
,
CGFloat
))
->
MotionAnimation
{
static
func
depth
(
_
depth
:
(
CGSize
,
Float
,
CGFloat
))
->
MotionAnimation
{
return
.
depth
(
offset
:
depth
.
0
,
opacity
:
depth
.
1
,
radius
:
depth
.
2
)
return
.
depth
(
offset
:
depth
.
0
,
opacity
:
depth
.
1
,
radius
:
depth
.
2
)
}
}
...
@@ -364,7 +364,7 @@ extension MotionAnimation {
...
@@ -364,7 +364,7 @@ extension MotionAnimation {
- Parameter rect: A CGRect.
- Parameter rect: A CGRect.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
contents
(
rect
:
CGRect
)
->
MotionAnimation
{
static
func
contents
(
rect
:
CGRect
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
contentsRect
=
rect
$0
.
contentsRect
=
rect
}
}
...
@@ -375,7 +375,7 @@ extension MotionAnimation {
...
@@ -375,7 +375,7 @@ extension MotionAnimation {
- Parameter scale: A CGFloat.
- Parameter scale: A CGFloat.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
contents
(
scale
:
CGFloat
)
->
MotionAnimation
{
static
func
contents
(
scale
:
CGFloat
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
contentsScale
=
scale
$0
.
contentsScale
=
scale
}
}
...
@@ -386,24 +386,18 @@ extension MotionAnimation {
...
@@ -386,24 +386,18 @@ extension MotionAnimation {
- Parameter _ duration: A TimeInterval.
- Parameter _ duration: A TimeInterval.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
duration
(
_
duration
:
TimeInterval
)
->
MotionAnimation
{
static
func
duration
(
_
duration
:
TimeInterval
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
duration
=
duration
$0
.
duration
=
duration
}
}
}
}
/**
/**
Sets the view's animation duration to the longest
running animation.
*/
public
static
var
preferredDurationMatchesLongest
=
MotionAnimation
.
duration
(
.
infinity
)
/**
Delays the animation of a given view.
Delays the animation of a given view.
- Parameter _ time: TimeInterval.
- Parameter _ time: TimeInterval.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
delay
(
_
time
:
TimeInterval
)
->
MotionAnimation
{
static
func
delay
(
_
time
:
TimeInterval
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
delay
=
time
$0
.
delay
=
time
}
}
...
@@ -414,13 +408,22 @@ extension MotionAnimation {
...
@@ -414,13 +408,22 @@ extension MotionAnimation {
- Parameter _ timingFunction: A CAMediaTimingFunction.
- Parameter _ timingFunction: A CAMediaTimingFunction.
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
public
static
func
timingFunction
(
_
timingFunction
:
CAMediaTimingFunction
)
->
MotionAnimation
{
static
func
timingFunction
(
_
timingFunction
:
CAMediaTimingFunction
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
timingFunction
=
timingFunction
$0
.
timingFunction
=
timingFunction
}
}
}
}
/**
/**
Sets the view's timing function for the animation.
- Parameter type: A CAMediaTimingFunctionType.
- Returns: A MotionAnimation.
*/
static
func
timingFunction
(
type
:
CAMediaTimingFunctionType
)
->
MotionAnimation
{
return
.
timingFunction
(
CAMediaTimingFunction
.
from
(
mediaTimingFunctionType
:
type
))
}
/**
Available in iOS 9+, animates a view using the spring API,
Available in iOS 9+, animates a view using the spring API,
given a stiffness and damping.
given a stiffness and damping.
- Parameter stiffness: A CGFlloat.
- Parameter stiffness: A CGFlloat.
...
@@ -428,22 +431,20 @@ extension MotionAnimation {
...
@@ -428,22 +431,20 @@ extension MotionAnimation {
- Returns: A MotionAnimation.
- Returns: A MotionAnimation.
*/
*/
@available(iOS 9, *)
@available(iOS 9, *)
public
static
func
spring
(
stiffness
:
CGFloat
,
damping
:
CGFloat
)
->
MotionAnimation
{
static
func
spring
(
stiffness
:
CGFloat
,
damping
:
CGFloat
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
spring
=
(
stiffness
,
damping
)
$0
.
spring
=
(
stiffness
,
damping
)
}
}
}
}
/**
/**
Animates the natural curve of a view. A value of 1 represents
Creates a completion block handler that executed once tha animation
a curve in a downward direction, and a value of -1
is done.
represents a curve in an upward direction.
- Parameter _ execute: A callback to execute once completed.
- Parameter intensity: A CGFloat.
- Returns: A MotionAnimation.
*/
*/
public
static
func
arc
(
intensity
:
CGFloat
=
1
)
->
MotionAnimation
{
static
func
completion
(
_
execute
:
@escaping
()
->
Void
)
->
MotionAnimation
{
return
MotionAnimation
{
return
MotionAnimation
{
$0
.
arc
=
intensity
$0
.
completion
=
execute
}
}
}
}
}
}
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
...
@@ -36,18 +36,18 @@ public class MotionTransition {
...
@@ -36,18 +36,18 @@ public class MotionTransition {
An initializer that accepts a given callback.
An initializer that accepts a given callback.
- Parameter applyFunction: A given callback.
- Parameter applyFunction: A given callback.
*/
*/
public
init
(
applyFunction
:
@escaping
(
inout
MotionTransitionState
)
->
Void
)
{
init
(
applyFunction
:
@escaping
(
inout
MotionTransitionState
)
->
Void
)
{
apply
=
applyFunction
apply
=
applyFunction
}
}
}
}
extension
MotionTransition
{
public
extension
MotionTransition
{
/**
/**
Animates the view with a matching motion identifier.
Animates the view with a matching motion identifier.
- Parameter _ identifier: A String.
- Parameter _ identifier: A String.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
motionIdentifier
(
_
identifier
:
String
)
->
MotionTransition
{
static
func
motionIdentifier
(
_
identifier
:
String
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
motionIdentifier
=
identifier
$0
.
motionIdentifier
=
identifier
}
}
...
@@ -60,7 +60,7 @@ extension MotionTransition {
...
@@ -60,7 +60,7 @@ extension MotionTransition {
masksToBounds state.
masksToBounds state.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
masksToBounds
(
_
masksToBounds
:
Bool
)
->
MotionTransition
{
static
func
masksToBounds
(
_
masksToBounds
:
Bool
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
masksToBounds
=
masksToBounds
$0
.
masksToBounds
=
masksToBounds
}
}
...
@@ -72,7 +72,7 @@ extension MotionTransition {
...
@@ -72,7 +72,7 @@ extension MotionTransition {
- Parameter color: A UIColor.
- Parameter color: A UIColor.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
background
(
color
:
UIColor
)
->
MotionTransition
{
static
func
background
(
color
:
UIColor
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
backgroundColor
=
color
.
cgColor
$0
.
backgroundColor
=
color
.
cgColor
}
}
...
@@ -84,7 +84,7 @@ extension MotionTransition {
...
@@ -84,7 +84,7 @@ extension MotionTransition {
- Parameter color: A UIColor.
- Parameter color: A UIColor.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
border
(
color
:
UIColor
)
->
MotionTransition
{
static
func
border
(
color
:
UIColor
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
borderColor
=
color
.
cgColor
$0
.
borderColor
=
color
.
cgColor
}
}
...
@@ -96,7 +96,7 @@ extension MotionTransition {
...
@@ -96,7 +96,7 @@ extension MotionTransition {
- Parameter width: A CGFloat.
- Parameter width: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
border
(
width
:
CGFloat
)
->
MotionTransition
{
static
func
border
(
width
:
CGFloat
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
borderWidth
=
width
$0
.
borderWidth
=
width
}
}
...
@@ -108,7 +108,7 @@ extension MotionTransition {
...
@@ -108,7 +108,7 @@ extension MotionTransition {
- Parameter radius: A CGFloat.
- Parameter radius: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
corner
(
radius
:
CGFloat
)
->
MotionTransition
{
static
func
corner
(
radius
:
CGFloat
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
cornerRadius
=
radius
$0
.
cornerRadius
=
radius
}
}
...
@@ -120,7 +120,7 @@ extension MotionTransition {
...
@@ -120,7 +120,7 @@ extension MotionTransition {
- Parameter _ transform: A CATransform3D.
- Parameter _ transform: A CATransform3D.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
transform
(
_
transform
:
CATransform3D
)
->
MotionTransition
{
static
func
transform
(
_
transform
:
CATransform3D
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
transform
=
transform
$0
.
transform
=
transform
}
}
...
@@ -132,7 +132,7 @@ extension MotionTransition {
...
@@ -132,7 +132,7 @@ extension MotionTransition {
- Parameter _ perspective: A CGFloat.
- Parameter _ perspective: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
perspective
(
_
perspective
:
CGFloat
)
->
MotionTransition
{
static
func
perspective
(
_
perspective
:
CGFloat
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
var
t
=
$0
.
transform
??
CATransform3DIdentity
var
t
=
$0
.
transform
??
CATransform3DIdentity
t
.
m34
=
1
/
-
perspective
t
.
m34
=
1
/
-
perspective
...
@@ -148,7 +148,7 @@ extension MotionTransition {
...
@@ -148,7 +148,7 @@ extension MotionTransition {
- Parameter z: A CGFloat.
- Parameter z: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
rotate
(
x
:
CGFloat
=
0
,
y
:
CGFloat
=
0
,
z
:
CGFloat
=
0
)
->
MotionTransition
{
static
func
rotate
(
x
:
CGFloat
=
0
,
y
:
CGFloat
=
0
,
z
:
CGFloat
=
0
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
var
t
=
$0
.
transform
??
CATransform3DIdentity
var
t
=
$0
.
transform
??
CATransform3DIdentity
t
=
CATransform3DRotate
(
t
,
x
,
1
,
0
,
0
)
t
=
CATransform3DRotate
(
t
,
x
,
1
,
0
,
0
)
...
@@ -163,7 +163,7 @@ extension MotionTransition {
...
@@ -163,7 +163,7 @@ extension MotionTransition {
- Parameter z: A CGFloat, default is 0.
- Parameter z: A CGFloat, default is 0.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
rotate
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionTransition
{
static
func
rotate
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionTransition
{
return
.
rotate
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
return
.
rotate
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
}
}
...
@@ -172,7 +172,7 @@ extension MotionTransition {
...
@@ -172,7 +172,7 @@ extension MotionTransition {
- Parameter _ z: A CGFloat.
- Parameter _ z: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
rotate
(
_
z
:
CGFloat
)
->
MotionTransition
{
static
func
rotate
(
_
z
:
CGFloat
)
->
MotionTransition
{
return
.
rotate
(
z
:
z
)
return
.
rotate
(
z
:
z
)
}
}
...
@@ -183,7 +183,7 @@ extension MotionTransition {
...
@@ -183,7 +183,7 @@ extension MotionTransition {
- Parameter z: A CGFloat.
- Parameter z: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
scale
(
x
:
CGFloat
=
1
,
y
:
CGFloat
=
1
,
z
:
CGFloat
=
1
)
->
MotionTransition
{
static
func
scale
(
x
:
CGFloat
=
1
,
y
:
CGFloat
=
1
,
z
:
CGFloat
=
1
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
transform
=
CATransform3DScale
(
$0
.
transform
??
CATransform3DIdentity
,
x
,
y
,
z
)
$0
.
transform
=
CATransform3DScale
(
$0
.
transform
??
CATransform3DIdentity
,
x
,
y
,
z
)
}
}
...
@@ -194,7 +194,7 @@ extension MotionTransition {
...
@@ -194,7 +194,7 @@ extension MotionTransition {
- Parameter _ xy: A CGFloat.
- Parameter _ xy: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
scale
(
_
xy
:
CGFloat
)
->
MotionTransition
{
static
func
scale
(
_
xy
:
CGFloat
)
->
MotionTransition
{
return
.
scale
(
x
:
xy
,
y
:
xy
)
return
.
scale
(
x
:
xy
,
y
:
xy
)
}
}
...
@@ -206,7 +206,7 @@ extension MotionTransition {
...
@@ -206,7 +206,7 @@ extension MotionTransition {
- Parameter z: A CGFloat.
- Parameter z: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
translate
(
x
:
CGFloat
=
0
,
y
:
CGFloat
=
0
,
z
:
CGFloat
=
0
)
->
MotionTransition
{
static
func
translate
(
x
:
CGFloat
=
0
,
y
:
CGFloat
=
0
,
z
:
CGFloat
=
0
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
transform
=
CATransform3DTranslate
(
$0
.
transform
??
CATransform3DIdentity
,
x
,
y
,
z
)
$0
.
transform
=
CATransform3DTranslate
(
$0
.
transform
??
CATransform3DIdentity
,
x
,
y
,
z
)
}
}
...
@@ -219,7 +219,7 @@ extension MotionTransition {
...
@@ -219,7 +219,7 @@ extension MotionTransition {
- Parameter z: A CGFloat, default is 0.
- Parameter z: A CGFloat, default is 0.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
translate
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionTransition
{
static
func
translate
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionTransition
{
return
.
translate
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
return
.
translate
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
}
}
...
@@ -228,29 +228,29 @@ extension MotionTransition {
...
@@ -228,29 +228,29 @@ extension MotionTransition {
- Parameter _ point: A CGPoint.
- Parameter _ point: A CGPoint.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
position
(
_
point
:
CGPoint
)
->
MotionTransition
{
static
func
position
(
_
point
:
CGPoint
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
position
=
point
$0
.
position
=
point
}
}
}
}
/// Forces the view to not fade during a transition.
/// Forces the view to not fade during a transition.
public
static
var
forceNonFade
=
MotionTransition
{
static
var
forceNonFade
=
MotionTransition
{
$0
.
nonFade
=
true
$0
.
nonFade
=
true
}
}
/// Fades the view in during a transition.
/// Fades the view in during a transition.
public
static
var
fadeIn
=
MotionTransition
.
fade
(
1
)
static
var
fadeIn
=
MotionTransition
.
fade
(
1
)
/// Fades the view out during a transition.
/// Fades the view out during a transition.
public
static
var
fadeOut
=
MotionTransition
.
fade
(
0
)
static
var
fadeOut
=
MotionTransition
.
fade
(
0
)
/**
/**
Animates the view's current opacity to the given one.
Animates the view's current opacity to the given one.
- Parameter to opacity: A Double.
- Parameter to opacity: A Double.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
fade
(
_
opacity
:
Double
)
->
MotionTransition
{
static
func
fade
(
_
opacity
:
Double
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
opacity
=
opacity
$0
.
opacity
=
opacity
}
}
...
@@ -261,7 +261,7 @@ extension MotionTransition {
...
@@ -261,7 +261,7 @@ extension MotionTransition {
- Parameter _ position: An Int.
- Parameter _ position: An Int.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
zPosition
(
_
position
:
CGFloat
)
->
MotionTransition
{
static
func
zPosition
(
_
position
:
CGFloat
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
zPosition
=
position
$0
.
zPosition
=
position
}
}
...
@@ -272,7 +272,7 @@ extension MotionTransition {
...
@@ -272,7 +272,7 @@ extension MotionTransition {
- Parameter _ size: A CGSize.
- Parameter _ size: A CGSize.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
size
(
_
size
:
CGSize
)
->
MotionTransition
{
static
func
size
(
_
size
:
CGSize
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
size
=
size
$0
.
size
=
size
}
}
...
@@ -283,7 +283,7 @@ extension MotionTransition {
...
@@ -283,7 +283,7 @@ extension MotionTransition {
- Parameter path: A CGPath.
- Parameter path: A CGPath.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
shadow
(
path
:
CGPath
)
->
MotionTransition
{
static
func
shadow
(
path
:
CGPath
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
shadowPath
=
path
$0
.
shadowPath
=
path
}
}
...
@@ -294,7 +294,7 @@ extension MotionTransition {
...
@@ -294,7 +294,7 @@ extension MotionTransition {
- Parameter color: A UIColor.
- Parameter color: A UIColor.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
shadow
(
color
:
UIColor
)
->
MotionTransition
{
static
func
shadow
(
color
:
UIColor
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
shadowColor
=
color
.
cgColor
$0
.
shadowColor
=
color
.
cgColor
}
}
...
@@ -305,7 +305,7 @@ extension MotionTransition {
...
@@ -305,7 +305,7 @@ extension MotionTransition {
- Parameter offset: A CGSize.
- Parameter offset: A CGSize.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
shadow
(
offset
:
CGSize
)
->
MotionTransition
{
static
func
shadow
(
offset
:
CGSize
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
shadowOffset
=
offset
$0
.
shadowOffset
=
offset
}
}
...
@@ -316,7 +316,7 @@ extension MotionTransition {
...
@@ -316,7 +316,7 @@ extension MotionTransition {
- Parameter opacity: A Float.
- Parameter opacity: A Float.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
shadow
(
opacity
:
Float
)
->
MotionTransition
{
static
func
shadow
(
opacity
:
Float
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
shadowOpacity
=
opacity
$0
.
shadowOpacity
=
opacity
}
}
...
@@ -327,7 +327,7 @@ extension MotionTransition {
...
@@ -327,7 +327,7 @@ extension MotionTransition {
- Parameter radius: A CGFloat.
- Parameter radius: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
shadow
(
radius
:
CGFloat
)
->
MotionTransition
{
static
func
shadow
(
radius
:
CGFloat
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
shadowRadius
=
radius
$0
.
shadowRadius
=
radius
}
}
...
@@ -338,7 +338,7 @@ extension MotionTransition {
...
@@ -338,7 +338,7 @@ extension MotionTransition {
- Parameter rect: A CGRect.
- Parameter rect: A CGRect.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
contents
(
rect
:
CGRect
)
->
MotionTransition
{
static
func
contents
(
rect
:
CGRect
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
contentsRect
=
rect
$0
.
contentsRect
=
rect
}
}
...
@@ -349,7 +349,7 @@ extension MotionTransition {
...
@@ -349,7 +349,7 @@ extension MotionTransition {
- Parameter scale: A CGFloat.
- Parameter scale: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
contents
(
scale
:
CGFloat
)
->
MotionTransition
{
static
func
contents
(
scale
:
CGFloat
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
contentsScale
=
scale
$0
.
contentsScale
=
scale
}
}
...
@@ -360,7 +360,7 @@ extension MotionTransition {
...
@@ -360,7 +360,7 @@ extension MotionTransition {
- Parameter _ duration: A TimeInterval.
- Parameter _ duration: A TimeInterval.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
duration
(
_
duration
:
TimeInterval
)
->
MotionTransition
{
static
func
duration
(
_
duration
:
TimeInterval
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
duration
=
duration
$0
.
duration
=
duration
}
}
...
@@ -370,31 +370,40 @@ extension MotionTransition {
...
@@ -370,31 +370,40 @@ extension MotionTransition {
Sets the view's animation duration to the longest
Sets the view's animation duration to the longest
running animation within a transition.
running animation within a transition.
*/
*/
public
static
var
preferredDurationMatchesLongest
=
MotionTransition
.
duration
(
.
infinity
)
static
var
preferredDurationMatchesLongest
=
MotionTransition
.
duration
(
.
infinity
)
/**
/**
Delays the animation of a given view.
Delays the animation of a given view.
- Parameter _ time: TimeInterval.
- Parameter _ time: TimeInterval.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
delay
(
_
time
:
TimeInterval
)
->
MotionTransition
{
static
func
delay
(
_
time
:
TimeInterval
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
delay
=
time
$0
.
delay
=
time
}
}
}
}
/**
/**
Sets the view's timing function for the
anima
tion.
Sets the view's timing function for the
transi
tion.
- Parameter _ timingFunction: A CAMediaTimingFunction.
- Parameter _ timingFunction: A CAMediaTimingFunction.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
timingFunction
(
_
timingFunction
:
CAMediaTimingFunction
)
->
MotionTransition
{
static
func
timingFunction
(
_
timingFunction
:
CAMediaTimingFunction
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
timingFunction
=
timingFunction
$0
.
timingFunction
=
timingFunction
}
}
}
}
/**
/**
Sets the view's timing function for the transition.
- Parameter type: A CAMediaTimingFunctionType.
- Returns: A MotionAnimation.
*/
static
func
timingFunction
(
type
:
CAMediaTimingFunctionType
)
->
MotionTransition
{
return
.
timingFunction
(
CAMediaTimingFunction
.
from
(
mediaTimingFunctionType
:
type
))
}
/**
Available in iOS 9+, animates a view using the spring API,
Available in iOS 9+, animates a view using the spring API,
given a stiffness and damping.
given a stiffness and damping.
- Parameter stiffness: A CGFlloat.
- Parameter stiffness: A CGFlloat.
...
@@ -402,7 +411,7 @@ extension MotionTransition {
...
@@ -402,7 +411,7 @@ extension MotionTransition {
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
@available(iOS 9, *)
@available(iOS 9, *)
public
static
func
spring
(
stiffness
:
CGFloat
,
damping
:
CGFloat
)
->
MotionTransition
{
static
func
spring
(
stiffness
:
CGFloat
,
damping
:
CGFloat
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
spring
=
(
stiffness
,
damping
)
$0
.
spring
=
(
stiffness
,
damping
)
}
}
...
@@ -415,7 +424,7 @@ extension MotionTransition {
...
@@ -415,7 +424,7 @@ extension MotionTransition {
- Parameter intensity: A CGFloat.
- Parameter intensity: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
arc
(
intensity
:
CGFloat
=
1
)
->
MotionTransition
{
static
func
arc
(
intensity
:
CGFloat
=
1
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
arc
=
intensity
$0
.
arc
=
intensity
}
}
...
@@ -429,7 +438,7 @@ extension MotionTransition {
...
@@ -429,7 +438,7 @@ extension MotionTransition {
or not to delay the subview animation until all have started.
or not to delay the subview animation until all have started.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
cascade
(
delta
:
TimeInterval
=
0.02
,
direction
:
CascadeDirection
=
.
topToBottom
,
animationDelayUntilMatchedViews
:
Bool
=
false
)
->
MotionTransition
{
static
func
cascade
(
delta
:
TimeInterval
=
0.02
,
direction
:
CascadeDirection
=
.
topToBottom
,
animationDelayUntilMatchedViews
:
Bool
=
false
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
cascade
=
(
delta
,
direction
,
animationDelayUntilMatchedViews
)
$0
.
cascade
=
(
delta
,
direction
,
animationDelayUntilMatchedViews
)
}
}
...
@@ -441,21 +450,21 @@ extension MotionTransition {
...
@@ -441,21 +450,21 @@ extension MotionTransition {
- Parameter opacity: A CGFloat.
- Parameter opacity: A CGFloat.
- Returns: A MotionTransition.
- Returns: A MotionTransition.
*/
*/
public
static
func
overlay
(
color
:
UIColor
,
opacity
:
CGFloat
)
->
MotionTransition
{
static
func
overlay
(
color
:
UIColor
,
opacity
:
CGFloat
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
overlay
=
(
color
.
cgColor
,
opacity
)
$0
.
overlay
=
(
color
.
cgColor
,
opacity
)
}
}
}
}
}
}
extension
MotionTransition
{
public
extension
MotionTransition
{
/**
/**
Apply transitions directly to the view at the start of the transition.
Apply transitions directly to the view at the start of the transition.
The transitions supplied here won't be animated.
The transitions supplied here won't be animated.
For source views, transitions are set directly at the begining of the animation.
For source views, transitions are set directly at the begining of the animation.
For destination views, they replace the target state (final appearance).
For destination views, they replace the target state (final appearance).
*/
*/
public
static
func
beginWith
(
transitions
:
[
MotionTransition
])
->
MotionTransition
{
static
func
beginWith
(
transitions
:
[
MotionTransition
])
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
if
$0
.
beginState
==
nil
{
if
$0
.
beginState
==
nil
{
$0
.
beginState
=
MotionTransitionStateWrapper
(
state
:
[])
$0
.
beginState
=
MotionTransitionStateWrapper
(
state
:
[])
...
@@ -471,7 +480,7 @@ extension MotionTransition {
...
@@ -471,7 +480,7 @@ extension MotionTransition {
For source views, transitions are set directly at the begining of the animation.
For source views, transitions are set directly at the begining of the animation.
For destination views, they replace the target state (final appearance).
For destination views, they replace the target state (final appearance).
*/
*/
public
static
func
beginWithIfMatched
(
transitions
:
[
MotionTransition
])
->
MotionTransition
{
static
func
beginWithIfMatched
(
transitions
:
[
MotionTransition
])
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
if
$0
.
beginStateIfMatched
==
nil
{
if
$0
.
beginStateIfMatched
==
nil
{
$0
.
beginStateIfMatched
=
[]
$0
.
beginStateIfMatched
=
[]
...
@@ -491,24 +500,24 @@ extension MotionTransition {
...
@@ -491,24 +500,24 @@ extension MotionTransition {
When a view is matched, this is automatically enabled.
When a view is matched, this is automatically enabled.
The `source` transition will also enable this.
The `source` transition will also enable this.
*/
*/
public
static
var
useGlobalCoordinateSpace
=
MotionTransition
{
static
var
useGlobalCoordinateSpace
=
MotionTransition
{
$0
.
coordinateSpace
=
.
global
$0
.
coordinateSpace
=
.
global
}
}
/// Use same parent coordinate space.
/// Use same parent coordinate space.
public
static
var
useSameParentCoordinateSpace
=
MotionTransition
{
static
var
useSameParentCoordinateSpace
=
MotionTransition
{
$0
.
coordinateSpace
=
.
sameParent
$0
.
coordinateSpace
=
.
sameParent
}
}
/// Ignore all motion transition attributes for a view's direct subviews.
/// Ignore all motion transition attributes for a view's direct subviews.
public
static
var
ignoreSubviewTransitions
:
MotionTransition
=
.
ignoreSubviewTransitions
()
static
var
ignoreSubviewTransitions
:
MotionTransition
=
.
ignoreSubviewTransitions
()
/**
/**
Ignore all motion transition attributes for a view's subviews.
Ignore all motion transition attributes for a view's subviews.
- Parameter recursive: If false, will only ignore direct subviews' transitions.
- Parameter recursive: If false, will only ignore direct subviews' transitions.
default false.
default false.
*/
*/
public
static
func
ignoreSubviewTransitions
(
recursive
:
Bool
=
false
)
->
MotionTransition
{
static
func
ignoreSubviewTransitions
(
recursive
:
Bool
=
false
)
->
MotionTransition
{
return
MotionTransition
{
return
MotionTransition
{
$0
.
ignoreSubviewTransitions
=
recursive
$0
.
ignoreSubviewTransitions
=
recursive
}
}
...
@@ -522,12 +531,12 @@ extension MotionTransition {
...
@@ -522,12 +531,12 @@ extension MotionTransition {
This transition actually does nothing by itself since .useOptimizedSnapshot is the default.
This transition actually does nothing by itself since .useOptimizedSnapshot is the default.
*/
*/
public
static
var
useOptimizedSnapshot
=
MotionTransition
{
static
var
useOptimizedSnapshot
=
MotionTransition
{
$0
.
snapshotType
=
.
optimized
$0
.
snapshotType
=
.
optimized
}
}
/// Create a snapshot using snapshotView(afterScreenUpdates:).
/// Create a snapshot using snapshotView(afterScreenUpdates:).
public
static
var
useNormalSnapshot
=
MotionTransition
{
static
var
useNormalSnapshot
=
MotionTransition
{
$0
.
snapshotType
=
.
normal
$0
.
snapshotType
=
.
normal
}
}
...
@@ -536,7 +545,7 @@ extension MotionTransition {
...
@@ -536,7 +545,7 @@ extension MotionTransition {
This is slower than .useNormalSnapshot but gives more accurate snapshots for some views
This is slower than .useNormalSnapshot but gives more accurate snapshots for some views
(eg. UIStackView).
(eg. UIStackView).
*/
*/
public
static
var
useLayerRenderSnapshot
=
MotionTransition
{
static
var
useLayerRenderSnapshot
=
MotionTransition
{
$0
.
snapshotType
=
.
layerRender
$0
.
snapshotType
=
.
layerRender
}
}
...
@@ -545,7 +554,7 @@ extension MotionTransition {
...
@@ -545,7 +554,7 @@ extension MotionTransition {
This will mess up the view hierarchy, therefore, view controllers have to rebuild
This will mess up the view hierarchy, therefore, view controllers have to rebuild
their view structure after the transition finishes.
their view structure after the transition finishes.
*/
*/
public
static
var
useNoSnapshot
=
MotionTransition
{
static
var
useNoSnapshot
=
MotionTransition
{
$0
.
snapshotType
=
.
noSnapshot
$0
.
snapshotType
=
.
noSnapshot
}
}
...
@@ -553,7 +562,7 @@ extension MotionTransition {
...
@@ -553,7 +562,7 @@ extension MotionTransition {
Force the view to animate (Motion will create animation contexts & snapshots for them, so
Force the view to animate (Motion will create animation contexts & snapshots for them, so
that they can be interactive).
that they can be interactive).
*/
*/
public
static
var
forceAnimate
=
MotionTransition
{
static
var
forceAnimate
=
MotionTransition
{
$0
.
forceAnimate
=
true
$0
.
forceAnimate
=
true
}
}
...
@@ -562,7 +571,7 @@ extension MotionTransition {
...
@@ -562,7 +571,7 @@ extension MotionTransition {
a .scale transition. This is to help Motion animate layers that doesn't support bounds animations.
a .scale transition. This is to help Motion animate layers that doesn't support bounds animations.
This also gives better performance.
This also gives better performance.
*/
*/
public
static
var
useScaleBasedSizeChange
=
MotionTransition
{
static
var
useScaleBasedSizeChange
=
MotionTransition
{
$0
.
useScaleBasedSizeChange
=
true
$0
.
useScaleBasedSizeChange
=
true
}
}
}
}
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