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
a8b1aa0e
Unverified
Commit
a8b1aa0e
authored
Jun 28, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated Motion to handle depth animations
parent
7a6f9cbd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
120 deletions
+88
-120
Sources/Extensions/Motion+CALayer.swift
+38
-75
Sources/MotionAnimation.swift
+45
-37
Sources/MotionAnimationState.swift
+0
-3
Sources/MotionTransition.swift
+5
-5
No files found.
Sources/Extensions/Motion+CALayer.swift
View file @
a8b1aa0e
...
...
@@ -147,7 +147,6 @@ fileprivate extension CALayer {
- Parameter completion: An optional completion block.
*/
func
animate
(
delay
:
TimeInterval
,
duration
:
TimeInterval
,
timingFunction
:
CAMediaTimingFunctionType
,
animations
:
[
MotionAnimation
],
completion
:
(()
->
Void
)?
=
nil
)
{
let
targetState
=
MotionAnimationState
(
animations
:
animations
)
Motion
.
delay
(
targetState
.
delay
)
{
[
weak
self
]
in
...
...
@@ -156,32 +155,10 @@ fileprivate extension CALayer {
}
var
anims
=
[
CABasicAnimation
]()
let
tf
:
CAMediaTimingFunction
=
targetState
.
timingFunction
??
CAMediaTimingFunction
.
from
(
mediaTimingFunctionType
:
timingFunction
)
let
d
:
TimeInterval
=
targetState
.
duration
??
duration
//
// var w: CGFloat = s.bounds.width
// var h: CGFloat = s.bounds.height
//
//
// var px: CGFloat = s.position.x
// var py: CGFloat = s.position.y
//
// for v in animations {
// switch v {
// case let .x(x):
// px = x + w / 2
//
// case let .y(y):
// py = y + h / 2
//
// case let .point(x, y):
// px = x + w / 2
// py = y + h / 2
//
// default:break
// }
// }
//
if
let
v
=
targetState
.
backgroundColor
{
let
a
=
MotionBasicAnimation
.
background
(
color
:
UIColor
(
cgColor
:
v
))
a
.
fromValue
=
s
.
backgroundColor
...
...
@@ -244,56 +221,42 @@ fileprivate extension CALayer {
anims
.
append
(
a
)
}
// case .width(_), .height(_), .size(_, _):
// a.append(MotionBasicAnimation.size(CGSize(width: w, height: h)))
//
// case let .shadowPath(path):
// let shadowPath = MotionBasicAnimation.shadow(path: path)
// shadowPath.fromValue = s.shadowPath
// a.append(shadowPath)
//
// case let .shadowColor(color):
// a.append(MotionBasicAnimation.shadow(color: color))
//
// case let .shadowOffset(offset):
// let shadowOffset = MotionBasicAnimation.shadow(offset: offset)
// shadowOffset.fromValue = s.shadowOffset
// a.append(shadowOffset)
//
// case let .shadowOpacity(opacity):
// let shadowOpacity = MotionBasicAnimation.shadow(opacity: opacity)
// shadowOpacity.fromValue = s.shadowOpacity
// a.append(shadowOpacity)
//
// case let .shadowRadius(radius):
// let shadowRadius = MotionBasicAnimation.shadow(radius: radius)
// shadowRadius.fromValue = s.shadowRadius
// a.append(shadowRadius)
//
// case let .depth(offset, opacity, radius):
// if let path = s.shadowPath {
// let shadowPath = MotionBasicAnimation.shadow(path: path)
// shadowPath.fromValue = s.shadowPath
// a.append(shadowPath)
// }
//
// let shadowOffset = MotionBasicAnimation.shadow(offset: offset)
// shadowOffset.fromValue = s.shadowOffset
// a.append(shadowOffset)
//
// let shadowOpacity = MotionBasicAnimation.shadow(opacity: opacity)
// shadowOpacity.fromValue = s.shadowOpacity
// a.append(shadowOpacity)
//
// let shadowRadius = MotionBasicAnimation.shadow(radius: radius)
// shadowRadius.fromValue = s.shadowRadius
// a.append(shadowRadius)
//
// default:break
// }
// }
//
if
let
v
=
targetState
.
size
{
let
a
=
MotionBasicAnimation
.
size
(
v
)
a
.
fromValue
=
NSValue
(
cgSize
:
s
.
bounds
.
size
)
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
shadowPath
{
let
a
=
MotionBasicAnimation
.
shadow
(
path
:
v
)
a
.
fromValue
=
s
.
shadowPath
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
shadowColor
{
let
a
=
MotionBasicAnimation
.
shadow
(
color
:
UIColor
(
cgColor
:
v
))
a
.
fromValue
=
s
.
shadowColor
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
shadowOffset
{
let
a
=
MotionBasicAnimation
.
shadow
(
offset
:
v
)
a
.
fromValue
=
NSValue
(
cgSize
:
s
.
shadowOffset
)
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
shadowOpacity
{
let
a
=
MotionBasicAnimation
.
shadow
(
opacity
:
v
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
Double
(
s
.
shadowOpacity
))
anims
.
append
(
a
)
}
if
let
v
=
targetState
.
shadowRadius
{
let
a
=
MotionBasicAnimation
.
shadow
(
radius
:
v
)
a
.
fromValue
=
NSNumber
(
floatLiteral
:
Double
(
s
.
shadowRadius
))
anims
.
append
(
a
)
}
let
g
=
Motion
.
animate
(
group
:
anims
,
duration
:
d
)
g
.
fillMode
=
MotionAnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
isRemovedOnCompletion
=
false
...
...
Sources/MotionAnimation.swift
View file @
a8b1aa0e
...
...
@@ -28,7 +28,7 @@
import
UIKit
public
final
class
MotionAnimation
{
public
class
MotionAnimation
{
/// A reference to the callback that applies the MotionAnimationState.
internal
let
apply
:
(
inout
MotionAnimationState
)
->
Void
...
...
@@ -251,7 +251,7 @@ extension MotionAnimation {
/**
Animates the view's current opacity to the given one.
- Parameter _ opacity: A Double
value
.
- Parameter _ opacity: A Double.
- Returns: A MotionAnimation.
*/
public
static
func
fade
(
_
opacity
:
Double
)
->
MotionAnimation
{
...
...
@@ -317,12 +317,12 @@ extension MotionAnimation {
/**
Animates the view's current shadow opacity to the given one.
- Parameter opacity: A
CG
Float.
- Parameter opacity: A Float.
- Returns: A MotionAnimation.
*/
public
static
func
shadow
(
opacity
:
CG
Float
)
->
MotionAnimation
{
public
static
func
shadow
(
opacity
:
Float
)
->
MotionAnimation
{
return
MotionAnimation
{
$0
.
shadowOpacity
=
Float
(
opacity
)
$0
.
shadowOpacity
=
opacity
}
}
...
...
@@ -338,6 +338,28 @@ extension MotionAnimation {
}
/**
Animates the views shadow offset, opacity, and radius.
- Parameter offset: A CGSize.
- Parameter opacity: A Float.
- Parameter radius: A CGFloat.
*/
public
static
func
depth
(
offset
:
CGSize
,
opacity
:
Float
,
radius
:
CGFloat
)
->
MotionAnimation
{
return
MotionAnimation
{
$0
.
shadowOffset
=
offset
$0
.
shadowOpacity
=
opacity
$0
.
shadowRadius
=
radius
}
}
/**
Animates the views shadow offset, opacity, and radius.
- Parameter _ depth: A tuple (CGSize, FLoat, CGFloat).
*/
public
static
func
depth
(
_
depth
:
(
CGSize
,
Float
,
CGFloat
))
->
MotionAnimation
{
return
.
depth
(
offset
:
depth
.
0
,
opacity
:
depth
.
1
,
radius
:
depth
.
2
)
}
/**
Animates the view's contents rect to the given one.
- Parameter rect: A CGRect.
- Returns: A MotionAnimation.
...
...
@@ -424,20 +446,6 @@ extension MotionAnimation {
$0
.
arc
=
intensity
}
}
/**
Animates subviews with an increasing delay between each animation.
- Parameter delta: A TimeInterval.
- Parameter direction: A CascadeDirection.
- Parameter animationDelayUntilMatchedViews: A boolean indicating whether
or not to delay the subview animation until all have started.
- Returns: A MotionAnimation.
*/
public
static
func
cascade
(
delta
:
TimeInterval
=
0.02
,
direction
:
CascadeDirection
=
.
topToBottom
,
animationDelayUntilMatchedViews
:
Bool
=
false
)
->
MotionAnimation
{
return
MotionAnimation
{
$0
.
cascade
=
(
delta
,
direction
,
animationDelayUntilMatchedViews
)
}
}
}
public
enum
MotionAnimationKeyPath
:
String
{
...
...
@@ -599,9 +607,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation.
*/
public
static
func
fade
(
_
opacity
:
Double
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
opacity
)
a
nimation
.
toValue
=
NSNumber
(
floatLiteral
:
opacity
)
return
a
nimation
let
a
=
CABasicAnimation
(
keyPath
:
.
opacity
)
a
.
toValue
=
NSNumber
(
floatLiteral
:
opacity
)
return
a
}
/**
...
...
@@ -610,9 +618,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation.
*/
public
static
func
zPosition
(
_
position
:
CGFloat
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
zPosition
)
a
nimation
.
toValue
=
NSNumber
(
value
:
Double
(
position
))
return
a
nimation
let
a
=
CABasicAnimation
(
keyPath
:
.
zPosition
)
a
.
toValue
=
NSNumber
(
value
:
Double
(
position
))
return
a
}
/**
...
...
@@ -621,9 +629,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation.
*/
public
static
func
width
(
_
width
:
CGFloat
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
width
)
a
nimation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
width
))
return
a
nimation
let
a
=
CABasicAnimation
(
keyPath
:
.
width
)
a
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
width
))
return
a
}
/**
...
...
@@ -632,9 +640,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation.
*/
public
static
func
height
(
_
height
:
CGFloat
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
height
)
a
nimation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
height
))
return
a
nimation
let
a
=
CABasicAnimation
(
keyPath
:
.
height
)
a
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
height
))
return
a
}
/**
...
...
@@ -643,9 +651,9 @@ public struct MotionBasicAnimation {
- Returns: A CABasicAnimation.
*/
public
static
func
size
(
_
size
:
CGSize
)
->
CABasicAnimation
{
let
a
nimation
=
CABasicAnimation
(
keyPath
:
.
size
)
a
nimation
.
toValue
=
NSValue
(
cgSize
:
size
)
return
a
nimation
let
a
=
CABasicAnimation
(
keyPath
:
.
size
)
a
.
toValue
=
NSValue
(
cgSize
:
size
)
return
a
}
/**
...
...
@@ -672,7 +680,7 @@ public struct MotionBasicAnimation {
/**
Creates a CABasicAnimation for the shadowOffset key path.
- Parameter offset: CGSize.
- Parameter offset:
A
CGSize.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
offset
:
CGSize
)
->
CABasicAnimation
{
...
...
@@ -683,7 +691,7 @@ public struct MotionBasicAnimation {
/**
Creates a CABasicAnimation for the shadowOpacity key path.
- Parameter opacity: Float.
- Parameter opacity:
A
Float.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
opacity
:
Float
)
->
CABasicAnimation
{
...
...
@@ -694,7 +702,7 @@ public struct MotionBasicAnimation {
/**
Creates a CABasicAnimation for the shadowRadius key path.
- Parameter radius: CGFloat.
- Parameter radius:
A
CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
shadow
(
radius
:
CGFloat
)
->
CABasicAnimation
{
...
...
Sources/MotionAnimationState.swift
View file @
a8b1aa0e
...
...
@@ -95,9 +95,6 @@ public struct MotionAnimationState {
/// The arc curve value.
public
var
arc
:
CGFloat
?
/// The cascading animation settings.
public
var
cascade
:
(
TimeInterval
,
CascadeDirection
,
Bool
)?
/// Custom target states.
public
var
custom
:
[
String
:
Any
]?
...
...
Sources/MotionTransition.swift
View file @
a8b1aa0e
...
...
@@ -28,7 +28,7 @@
import
UIKit
public
final
class
MotionTransition
{
public
class
MotionTransition
{
/// A reference to the callback that applies the MotionTransitionState.
internal
let
apply
:
(
inout
MotionTransitionState
)
->
Void
...
...
@@ -247,7 +247,7 @@ extension MotionTransition {
/**
Animates the view's current opacity to the given one.
- Parameter to opacity: A Double
value
.
- Parameter to opacity: A Double.
- Returns: A MotionTransition.
*/
public
static
func
fade
(
_
opacity
:
Double
)
->
MotionTransition
{
...
...
@@ -313,12 +313,12 @@ extension MotionTransition {
/**
Animates the view's current shadow opacity to the given one.
- Parameter opacity: A
CG
Float.
- Parameter opacity: A Float.
- Returns: A MotionTransition.
*/
public
static
func
shadow
(
opacity
:
CG
Float
)
->
MotionTransition
{
public
static
func
shadow
(
opacity
:
Float
)
->
MotionTransition
{
return
MotionTransition
{
$0
.
shadowOpacity
=
Float
(
opacity
)
$0
.
shadowOpacity
=
opacity
}
}
...
...
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