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
7a6f9cbd
Unverified
Commit
7a6f9cbd
authored
Jun 28, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated MotionAnimation and MotionTransition APIs
parent
06f6c0cd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
148 additions
and
281 deletions
+148
-281
Sources/Extensions/Motion+CALayer.swift
+44
-68
Sources/MotionAnimation.swift
+57
-167
Sources/MotionAnimationState.swift
+7
-7
Sources/MotionTransition.swift
+13
-12
Sources/MotionTransitionState.swift
+7
-7
Sources/TransitionPreprocessor.swift
+20
-20
No files found.
Sources/Extensions/Motion+CALayer.swift
View file @
7a6f9cbd
...
...
@@ -155,7 +155,7 @@ fileprivate extension CALayer {
return
}
var
a
=
[
CABasicAnimation
]()
var
a
nims
=
[
CABasicAnimation
]()
let
tf
:
CAMediaTimingFunction
=
targetState
.
timingFunction
??
CAMediaTimingFunction
.
from
(
mediaTimingFunctionType
:
timingFunction
)
let
d
:
TimeInterval
=
targetState
.
duration
??
duration
//
...
...
@@ -183,92 +183,68 @@ fileprivate extension CALayer {
// }
//
if
let
v
=
targetState
.
backgroundColor
{
let
a
nim
=
MotionBasicAnimation
.
background
(
color
:
UIColor
(
cgColor
:
v
))
a
nim
.
fromValue
=
s
.
backgroundColor
a
.
append
(
anim
)
let
a
=
MotionBasicAnimation
.
background
(
color
:
UIColor
(
cgColor
:
v
))
a
.
fromValue
=
s
.
backgroundColor
a
nims
.
append
(
a
)
}
if
let
v
=
targetState
.
borderColor
{
let
a
nim
=
MotionBasicAnimation
.
border
(
color
:
UIColor
(
cgColor
:
v
))
a
nim
.
fromValue
=
s
.
borderColor
a
.
append
(
anim
)
let
a
=
MotionBasicAnimation
.
border
(
color
:
UIColor
(
cgColor
:
v
))
a
.
fromValue
=
s
.
borderColor
a
nims
.
append
(
a
)
}
if
let
v
=
targetState
.
borderWidth
{
let
a
nim
=
MotionBasicAnimation
.
border
(
width
:
v
)
a
nim
.
fromValue
=
NSNumber
(
floatLiteral
:
Double
(
s
.
borderWidth
))
a
.
append
(
anim
)
let
a
=
MotionBasicAnimation
.
border
(
width
:
v
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
Double
(
s
.
borderWidth
))
a
nims
.
append
(
a
)
}
if
let
v
=
targetState
.
cornerRadius
{
let
a
nim
=
MotionBasicAnimation
.
corner
(
radius
:
v
)
a
nim
.
fromValue
=
NSNumber
(
floatLiteral
:
Double
(
s
.
cornerRadius
))
a
.
append
(
anim
)
let
a
=
MotionBasicAnimation
.
corner
(
radius
:
v
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
Double
(
s
.
cornerRadius
))
a
nims
.
append
(
a
)
}
if
let
v
=
targetState
.
transform
{
let
a
nim
=
MotionBasicAnimation
.
transform
(
transform
:
v
)
a
nim
.
fromValue
=
NSValue
(
caTransform3D
:
s
.
transform
)
a
.
append
(
anim
)
let
a
=
MotionBasicAnimation
.
transform
(
v
)
a
.
fromValue
=
NSValue
(
caTransform3D
:
s
.
transform
)
a
nims
.
append
(
a
)
}
if
let
v
=
targetState
.
spin
{
var
a
nim
=
MotionBasicAnimation
.
spinX
(
rotates
:
v
.
0
)
a
nim
.
fromValue
=
0
a
.
append
(
anim
)
var
a
=
MotionBasicAnimation
.
spinX
(
v
.
0
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
0
)
a
nims
.
append
(
a
)
a
nim
=
MotionBasicAnimation
.
spinY
(
rotates
:
v
.
1
)
a
nim
.
fromValue
=
0
a
.
append
(
anim
)
a
=
MotionBasicAnimation
.
spinY
(
v
.
1
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
0
)
a
nims
.
append
(
a
)
a
nim
=
MotionBasicAnimation
.
spinZ
(
rotates
:
v
.
2
)
a
nim
.
fromValue
=
0
a
.
append
(
anim
)
a
=
MotionBasicAnimation
.
spinZ
(
v
.
2
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
0
)
a
nims
.
append
(
a
)
}
if
let
v
=
targetState
.
position
{
let
a
=
MotionBasicAnimation
.
position
(
v
)
a
.
fromValue
=
NSValue
(
cgPoint
:
s
.
position
)
anims
.
append
(
a
)
}
//
// case let .scale(to):
// a.append(MotionBasicAnimation.scale(to: to))
//
// case let .scaleX(to):
// a.append(MotionBasicAnimation.scaleX(to: to))
//
// case let .scaleY(to):
// a.append(MotionBasicAnimation.scaleY(to: to))
//
// case let .scaleZ(to):
// a.append(MotionBasicAnimation.scaleZ(to: to))
//
// case let .translate(x, y):
// a.append(MotionBasicAnimation.translate(to: CGPoint(x: x, y: y)))
//
// case let .translateX(to):
// a.append(MotionBasicAnimation.translateX(to: to))
//
// case let .translateY(to):
// a.append(MotionBasicAnimation.translateY(to: to))
//
// case let .translateZ(to):
// a.append(MotionBasicAnimation.translateZ(to: to))
//
// case .x(_), .y(_), .point(_, _):
// let position = MotionBasicAnimation.position(to: CGPoint(x: px, y: py))
// a.append(position)
//
// case let .position(x, y):
// a.append(MotionBasicAnimation.position(to: CGPoint(x: x, y: y)))
//
// case let .fade(opacity):
// let fade = MotionBasicAnimation.fade(to: opacity)
// fade.fromValue = s.value(forKey: MotionAnimationKeyPath.opacity.rawValue) ?? NSNumber(floatLiteral: 1)
// a.append(fade)
//
// case let .zPosition(position):
// let zPosition = MotionBasicAnimation.zPosition(position)
// zPosition.fromValue = s.value(forKey: MotionAnimationKeyPath.zPosition.rawValue) ?? NSNumber(value: 0)
// a.append(zPosition)
//
if
let
v
=
targetState
.
opacity
{
let
a
=
MotionBasicAnimation
.
fade
(
v
)
a
.
fromValue
=
s
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
opacity
.
rawValue
)
??
NSNumber
(
floatLiteral
:
1
)
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
zPosition
{
let
a
=
MotionBasicAnimation
.
zPosition
(
v
)
a
.
fromValue
=
s
.
value
(
forKeyPath
:
MotionAnimationKeyPath
.
zPosition
.
rawValue
)
??
NSNumber
(
floatLiteral
:
0
)
anims
.
append
(
a
)
}
// case .width(_), .height(_), .size(_, _):
// a.append(MotionBasicAnimation.size(CGSize(width: w, height: h)))
//
...
...
@@ -318,7 +294,7 @@ fileprivate extension CALayer {
// }
// }
//
let
g
=
Motion
.
animate
(
group
:
a
,
duration
:
d
)
let
g
=
Motion
.
animate
(
group
:
a
nims
,
duration
:
d
)
g
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
isRemovedOnCompletion
=
false
g
.
timingFunction
=
tf
...
...
Sources/MotionAnimation.swift
View file @
7a6f9cbd
...
...
@@ -200,11 +200,11 @@ extension MotionAnimation {
/**
Animates the view's current x & y scale to the given scale value.
- Parameter
to scale
: A CGFloat.
- Parameter
_ xy
: A CGFloat.
- Returns: A MotionAnimation.
*/
public
static
func
scale
(
to
scale
:
CGFloat
)
->
MotionAnimation
{
return
.
scale
(
x
:
scale
,
y
:
scale
)
public
static
func
scale
(
_
xy
:
CGFloat
)
->
MotionAnimation
{
return
.
scale
(
x
:
xy
,
y
:
xy
)
}
/**
...
...
@@ -224,36 +224,37 @@ extension MotionAnimation {
/**
Animates the view's current translation to the given
point value (x & y), and a z value.
- Parameter
to
point: A CGPoint.
- Parameter
_
point: A CGPoint.
- Parameter z: A CGFloat, default is 0.
- Returns: A MotionAnimation.
*/
public
static
func
translate
(
to
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
public
static
func
translate
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionAnimation
{
return
.
translate
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
}
/**
Animates the view's current position to the given point.
- Parameter
to
point: A CGPoint.
- Parameter
_
point: A CGPoint.
- Returns: A MotionAnimation.
*/
public
static
func
position
(
to
point
:
CGPoint
)
->
MotionAnimation
{
public
static
func
position
(
_
point
:
CGPoint
)
->
MotionAnimation
{
return
MotionAnimation
{
$0
.
position
=
point
}
}
/// Fades the view out during a transition.
public
static
var
fade
=
MotionAnimation
{
$0
.
opacity
=
0
}
/// Fades the view in during an animation.
public
static
var
fadeIn
=
MotionAnimation
.
fade
(
1
)
/// Fades the view out during an animation.
public
static
var
fadeOut
=
MotionAnimation
.
fade
(
0
)
/**
Animates the view's current opacity to the given one.
- Parameter
to opacity: A Float
value.
- Parameter
_ opacity: A Double
value.
- Returns: A MotionAnimation.
*/
public
static
func
fade
(
to
opacity
:
Float
)
->
MotionAnimation
{
public
static
func
fade
(
_
opacity
:
Double
)
->
MotionAnimation
{
return
MotionAnimation
{
$0
.
opacity
=
opacity
}
...
...
@@ -371,7 +372,7 @@ extension MotionAnimation {
/**
Sets the view's animation duration to the longest
running animation
within a transition
.
running animation.
*/
public
static
var
preferredDurationMatchesLongest
=
MotionAnimation
.
duration
(
.
infinity
)
...
...
@@ -488,9 +489,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation.
*/
public
static
func
background
(
color
:
UIColor
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
backgroundColor
)
a
nimation
.
toValue
=
color
.
cgColor
return
a
nimation
let
a
=
CABasicAnimation
(
keyPath
:
.
backgroundColor
)
a
.
toValue
=
color
.
cgColor
return
a
}
/**
...
...
@@ -499,9 +500,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation.
*/
public
static
func
barTint
(
color
:
UIColor
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
barTintColor
)
a
nimation
.
toValue
=
color
.
cgColor
return
a
nimation
let
a
=
CABasicAnimation
(
keyPath
:
.
barTintColor
)
a
.
toValue
=
color
.
cgColor
return
a
}
/**
...
...
@@ -510,9 +511,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation.
*/
public
static
func
border
(
color
:
UIColor
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
borderColor
)
a
nimation
.
toValue
=
color
.
cgColor
return
a
nimation
let
a
=
CABasicAnimation
(
keyPath
:
.
borderColor
)
a
.
toValue
=
color
.
cgColor
return
a
}
/**
...
...
@@ -521,9 +522,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation.
*/
public
static
func
border
(
width
:
CGFloat
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
borderWidth
)
a
nimation
.
toValue
=
width
return
a
nimation
let
a
=
CABasicAnimation
(
keyPath
:
.
borderWidth
)
a
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
width
))
return
a
}
/**
...
...
@@ -532,183 +533,72 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation.
*/
public
static
func
corner
(
radius
:
CGFloat
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
cornerRadius
)
a
nimation
.
toValue
=
radius
return
a
nimation
let
a
=
CABasicAnimation
(
keyPath
:
.
cornerRadius
)
a
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
radius
))
return
a
}
/**
Creates a CABasicAnimation for the transform key path.
- Parameter transform: A CATransform3D object.
- Returns: A CABasicAnimation.
*/
public
static
func
transform
(
transform
:
CATransform3D
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
transform
)
animation
.
toValue
=
NSValue
(
caTransform3D
:
transform
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.rotate key path.
- Parameter rotates: An optional CGFloat.
- Parameter _ t: A CATransform3D object.
- Returns: A CABasicAnimation.
*/
public
static
func
spin
(
rotates
:
CGFloat
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
rotate
)
a
nimation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotates
)
)
return
a
nimation
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
rotate
s: An optional CGFloat.
- Parameter
_ rotation
s: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
spinX
(
rotate
s
:
CGFloat
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
rotateX
)
a
nimation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotate
s
))
return
a
nimation
public
static
func
spinX
(
_
rotation
s
:
CGFloat
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
rotateX
)
a
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotation
s
))
return
a
}
/**
Creates a CABasicAnimation for the transform.rotate.y key path.
- Parameter
rotate
s: An optional CGFloat.
- Parameter
_ rotation
s: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
spinY
(
rotate
s
:
CGFloat
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
rotateY
)
a
nimation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotate
s
))
return
a
nimation
public
static
func
spinY
(
_
rotation
s
:
CGFloat
)
->
CABasicAnimation
{
let
a
=
CABasicAnimation
(
keyPath
:
.
rotateY
)
a
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotation
s
))
return
a
}
/**
Creates a CABasicAnimation for the transform.rotate.z key path.
- Parameter
rotate
s: An optional CGFloat.
- Parameter
_ rotation
s: An optional CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
spinZ
(
rotates
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotateZ
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
CGFloat
(
Double
.
pi
)
*
2
*
rotates
))
return
animation
}
/**
Creates a CABasicAnimation for the transform.scale key path.
- Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
scale
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scale
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
scale
))
return
animation
}
/**
Creates a CABasicAnimation for the transform.scale.x key path.
- Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
scaleX
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleX
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
scale
))
return
animation
}
/**
Creates a CABasicAnimation for the transform.scale.y key path.
- Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
scaleY
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleY
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
scale
))
return
animation
}
/**
Creates a CABasicAnimation for the transform.scale.z key path.
- Parameter to scale: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
scaleZ
(
to
scale
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleZ
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
scale
))
return
animation
}
/**
Creates a CABasicAnimation for the transform.translation key path.
- Parameter point: A CGPoint.
- Returns: A CABasicAnimation.
*/
public
static
func
translate
(
to
point
:
CGPoint
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
translation
)
animation
.
toValue
=
NSValue
(
cgPoint
:
point
)
return
animation
}
/**
Creates a CABasicAnimation for the transform.translation.x key path.
- Parameter to translation: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
translateX
(
to
translation
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
translationX
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
translation
))
return
animation
}
/**
Creates a CABasicAnimation for the transform.translation.y key path.
- Parameter to translation: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
translateY
(
to
translation
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
translationY
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
translation
))
return
animation
}
/**
Creates a CABasicAnimation for the transform.translation.z key path.
- Parameter to translation: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
translateZ
(
to
translation
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
translationZ
)
animation
.
toValue
=
NSNumber
(
value
:
Double
(
translation
))
return
animation
}
/**
Creates a CABasicAnimation for the position key path.
- Parameter x: A CGFloat.
- Parameter y: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
position
(
x
:
CGFloat
,
y
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
position
)
animation
.
toValue
=
NSValue
(
cgPoint
:
CGPoint
(
x
:
x
,
y
:
y
))
return
animation
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
to
point: A CGPoint.
- Parameter
_
point: A CGPoint.
- Returns: A CABasicAnimation.
*/
public
static
func
position
(
to
point
:
CGPoint
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
position
)
a
nimation
.
toValue
=
NSValue
(
cgPoint
:
point
)
return
a
nimation
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
to
opacity: A Double.
- Parameter
_
opacity: A Double.
- Returns: A CABasicAnimation.
*/
public
static
func
fade
(
to
opacity
:
Double
)
->
CABasicAnimation
{
public
static
func
fade
(
_
opacity
:
Double
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
opacity
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
opacity
)
return
animation
...
...
Sources/MotionAnimationState.swift
View file @
7a6f9cbd
...
...
@@ -42,7 +42,7 @@ public struct MotionAnimationState {
public
var
spin
:
(
CGFloat
,
CGFloat
,
CGFloat
)?
/// A reference to the opacity.
public
var
opacity
:
Float
?
public
var
opacity
:
Double
?
/// A reference to the cornerRadius.
public
var
cornerRadius
:
CGFloat
?
...
...
@@ -113,18 +113,18 @@ public struct MotionAnimationState {
extension
MotionAnimationState
{
/**
Adds a MotionAnimation to the current state.
- Parameter _
animation
: A MotionAnimation.
- Parameter _
element
: A MotionAnimation.
*/
public
mutating
func
append
(
_
animation
:
MotionAnimation
)
{
animation
.
apply
(
&
self
)
public
mutating
func
append
(
_
element
:
MotionAnimation
)
{
element
.
apply
(
&
self
)
}
/**
Adds an Array of MotionAnimations to the current state.
- Parameter contentsOf
animation
s: An Array of MotionAnimations.
- Parameter contentsOf
element
s: An Array of MotionAnimations.
*/
public
mutating
func
append
(
contentsOf
animation
s
:
[
MotionAnimation
])
{
for
v
in
animation
s
{
public
mutating
func
append
(
contentsOf
element
s
:
[
MotionAnimation
])
{
for
v
in
element
s
{
v
.
apply
(
&
self
)
}
}
...
...
Sources/MotionTransition.swift
View file @
7a6f9cbd
...
...
@@ -191,11 +191,11 @@ extension MotionTransition {
/**
Animates the view's current x & y scale to the given scale value.
- Parameter
to scale
: A CGFloat.
- Parameter
_ xy
: A CGFloat.
- Returns: A MotionTransition.
*/
public
static
func
scale
(
to
scale
:
CGFloat
)
->
MotionTransition
{
return
.
scale
(
x
:
scale
,
y
:
scale
)
public
static
func
scale
(
_
xy
:
CGFloat
)
->
MotionTransition
{
return
.
scale
(
x
:
xy
,
y
:
xy
)
}
/**
...
...
@@ -215,20 +215,20 @@ extension MotionTransition {
/**
Animates the view's current translation to the given
point value (x & y), and a z value.
- Parameter
to
point: A CGPoint.
- Parameter
_
point: A CGPoint.
- Parameter z: A CGFloat, default is 0.
- Returns: A MotionTransition.
*/
public
static
func
translate
(
to
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionTransition
{
public
static
func
translate
(
_
point
:
CGPoint
,
z
:
CGFloat
=
0
)
->
MotionTransition
{
return
.
translate
(
x
:
point
.
x
,
y
:
point
.
y
,
z
:
z
)
}
/**
Animates the view's current position to the given point.
- Parameter
to
point: A CGPoint.
- Parameter
_
point: A CGPoint.
- Returns: A MotionTransition.
*/
public
static
func
position
(
to
point
:
CGPoint
)
->
MotionTransition
{
public
static
func
position
(
_
point
:
CGPoint
)
->
MotionTransition
{
return
MotionTransition
{
$0
.
position
=
point
}
...
...
@@ -239,17 +239,18 @@ extension MotionTransition {
$0
.
nonFade
=
true
}
/// Fades the view in during a transition.
public
static
var
fadeIn
=
MotionTransition
.
fade
(
1
)
/// Fades the view out during a transition.
public
static
var
fade
=
MotionTransition
{
$0
.
opacity
=
0
}
public
static
var
fadeOut
=
MotionTransition
.
fade
(
0
)
/**
Animates the view's current opacity to the given one.
- Parameter to opacity: A
Float
value.
- Parameter to opacity: A
Double
value.
- Returns: A MotionTransition.
*/
public
static
func
fade
(
to
opacity
:
Float
)
->
MotionTransition
{
public
static
func
fade
(
_
opacity
:
Double
)
->
MotionTransition
{
return
MotionTransition
{
$0
.
opacity
=
opacity
}
...
...
Sources/MotionTransitionState.swift
View file @
7a6f9cbd
...
...
@@ -58,7 +58,7 @@ public struct MotionTransitionState {
public
var
transform
:
CATransform3D
?
/// A reference to the opacity.
public
var
opacity
:
Float
?
public
var
opacity
:
Double
?
/// A reference to the cornerRadius.
public
var
cornerRadius
:
CGFloat
?
...
...
@@ -162,18 +162,18 @@ public struct MotionTransitionState {
extension
MotionTransitionState
{
/**
Adds a MotionTransition to the current state.
- Parameter _
transition
: A MotionTransition.
- Parameter _
element
: A MotionTransition.
*/
public
mutating
func
append
(
_
transition
:
MotionTransition
)
{
transition
.
apply
(
&
self
)
public
mutating
func
append
(
_
element
:
MotionTransition
)
{
element
.
apply
(
&
self
)
}
/**
Adds an Array of MotionTransitions to the current state.
- Parameter contentsOf
transition
s: An Array of MotionTransitions.
- Parameter contentsOf
element
s: An Array of MotionTransitions.
*/
public
mutating
func
append
(
contentsOf
transition
s
:
[
MotionTransition
])
{
for
v
in
transition
s
{
public
mutating
func
append
(
contentsOf
element
s
:
[
MotionTransition
])
{
for
v
in
element
s
{
v
.
apply
(
&
self
)
}
}
...
...
Sources/TransitionPreprocessor.swift
View file @
7a6f9cbd
...
...
@@ -261,37 +261,37 @@ class TransitionPreprocessor: MotionPreprocessor {
switch
defaultAnimation
{
case
.
push
(
let
direction
):
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
),
.
timingFunction
(
.
deceleration
)])
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)
/
3
),
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
)
/
3
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
.
timingFunction
(
.
deceleration
)])
case
.
pull
(
let
direction
):
m
.
insertToViewFirst
=
true
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
)])
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)
/
3
),
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
)
/
3
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
case
.
slide
(
let
direction
):
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
))])
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
))])
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
))])
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
))])
case
.
zoomSlide
(
let
direction
):
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
scale
(
to
:
0.8
)])
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
scale
(
0.8
)])
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
scale
(
to
:
0.8
)])
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
scale
(
0.8
)])
case
.
cover
(
let
direction
):
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
),
.
timingFunction
(
.
deceleration
)])
...
...
@@ -302,43 +302,43 @@ class TransitionPreprocessor: MotionPreprocessor {
case
.
uncover
(
let
direction
):
m
.
insertToViewFirst
=
true
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
)])
context
[
tv
]
!.
append
(
contentsOf
:
[
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
case
.
pageIn
(
let
direction
):
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
true
)),
context
[
tv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
true
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
),
.
timingFunction
(
.
deceleration
)])
context
[
fv
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
),
context
[
fv
]
!.
append
(
contentsOf
:
[
.
scale
(
0.7
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
),
.
timingFunction
(
.
deceleration
)])
case
.
pageOut
(
let
direction
):
m
.
insertToViewFirst
=
true
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
to
:
shift
(
direction
:
direction
,
isAppearing
:
false
)),
context
[
fv
]
!.
append
(
contentsOf
:
[
.
translate
(
shift
(
direction
:
direction
,
isAppearing
:
false
)),
.
shadow
(
opacity
:
0
),
.
beginWith
(
transitions
:
shadowState
)])
context
[
tv
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
),
context
[
tv
]
!.
append
(
contentsOf
:
[
.
scale
(
0.7
),
.
overlay
(
color
:
.
black
,
opacity
:
0.1
)])
case
.
fade
:
// TODO: clean up this. overFullScreen logic shouldn't be here
if
!
(
fromOverFullScreen
&&
!
isPresenting
)
{
context
[
tv
]
=
[
.
fade
]
context
[
tv
]
=
[
.
fade
Out
]
}
#if os(tvOS)
context
[
fromView
]
=
[
.
fade
]
#else
if
(
!
isPresenting
&&
toOverFullScreen
)
||
!
fv
.
isOpaque
||
(
fv
.
backgroundColor
?
.
alphaComponent
??
1
)
<
1
{
context
[
fv
]
=
[
.
fade
]
context
[
fv
]
=
[
.
fade
Out
]
}
#endif
...
...
@@ -347,12 +347,12 @@ class TransitionPreprocessor: MotionPreprocessor {
case
.
zoom
:
m
.
insertToViewFirst
=
true
context
[
fv
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
1.3
),
.
fade
])
context
[
tv
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
)])
context
[
fv
]
!.
append
(
contentsOf
:
[
.
scale
(
1.3
),
.
fadeOut
])
context
[
tv
]
!.
append
(
contentsOf
:
[
.
scale
(
0.7
)])
case
.
zoomOut
:
context
[
tv
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
1.3
),
.
fade
])
context
[
fv
]
!.
append
(
contentsOf
:
[
.
scale
(
to
:
0.7
)])
context
[
tv
]
!.
append
(
contentsOf
:
[
.
scale
(
1.3
),
.
fadeOut
])
context
[
fv
]
!.
append
(
contentsOf
:
[
.
scale
(
0.7
)])
default
:
fatalError
(
"Not implemented"
)
...
...
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