Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
Material
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
Material
Commits
b9f7bf00
Unverified
Commit
b9f7bf00
authored
Jan 09, 2017
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: added fade to MotionAnimation
parent
00a46e33
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
189 deletions
+48
-189
Sources/iOS/BasicMotion.swift
+38
-176
Sources/iOS/KeyframeMotion.swift
+1
-1
Sources/iOS/PulseMotion.swift
+9
-12
No files found.
Sources/iOS/BasicMotion.swift
View file @
b9f7bf00
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
import
UIKit
import
UIKit
public
enum
AnimationKeyPath
:
String
{
public
enum
Motion
AnimationKeyPath
:
String
{
case
backgroundColor
case
backgroundColor
case
cornerRadius
case
cornerRadius
case
transform
case
transform
...
@@ -48,6 +48,7 @@ public enum AnimationKeyPath: String {
...
@@ -48,6 +48,7 @@ public enum AnimationKeyPath: String {
case
translationZ
=
"transform.translation.z"
case
translationZ
=
"transform.translation.z"
case
position
case
position
case
shadowPath
case
shadowPath
case
opacity
}
}
public
enum
MotionAnimation
{
public
enum
MotionAnimation
{
...
@@ -72,6 +73,7 @@ public enum MotionAnimation {
...
@@ -72,6 +73,7 @@ public enum MotionAnimation {
case
moveZ
(
by
:
CGFloat
)
case
moveZ
(
by
:
CGFloat
)
case
position
(
to
:
CGPoint
)
case
position
(
to
:
CGPoint
)
case
shadow
(
path
:
CGPath
)
case
shadow
(
path
:
CGPath
)
case
fade
(
opacity
:
CGFloat
)
}
}
extension
CALayer
{
extension
CALayer
{
...
@@ -191,10 +193,19 @@ extension CALayer {
...
@@ -191,10 +193,19 @@ extension CALayer {
a
.
append
(
Motion
.
position
(
to
:
to
))
a
.
append
(
Motion
.
position
(
to
:
to
))
case
let
.
shadow
(
path
):
case
let
.
shadow
(
path
):
a
.
append
(
Motion
.
shadow
(
path
:
path
))
a
.
append
(
Motion
.
shadow
(
path
:
path
))
case
let
.
fade
(
opacity
):
let
fade
=
Motion
.
fade
(
opacity
:
opacity
)
fade
.
fromValue
=
value
(
forKey
:
MotionAnimationKeyPath
.
opacity
.
rawValue
)
??
NSNumber
(
floatLiteral
:
1
)
a
.
append
(
fade
)
}
}
}
}
animate
(
animation
:
Motion
.
animate
(
group
:
a
,
duration
:
duration
))
let
g
=
Motion
.
animate
(
group
:
a
,
duration
:
duration
)
g
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
g
.
isRemovedOnCompletion
=
false
g
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
animate
(
animation
:
g
)
}
}
open
func
motion
(
delay
:
TimeInterval
,
animations
:
MotionAnimation
...
)
{
open
func
motion
(
delay
:
TimeInterval
,
animations
:
MotionAnimation
...
)
{
...
@@ -274,403 +285,254 @@ extension UIView {
...
@@ -274,403 +285,254 @@ extension UIView {
extension
CABasicAnimation
{
extension
CABasicAnimation
{
/**
/**
A convenience initializer that takes a given AnimationKeyPath.
A convenience initializer that takes a given
Motion
AnimationKeyPath.
- Parameter keyPath: An AnimationKeyPath.
- Parameter keyPath: An
Motion
AnimationKeyPath.
*/
*/
public
convenience
init
(
keyPath
:
AnimationKeyPath
)
{
public
convenience
init
(
keyPath
:
Motion
AnimationKeyPath
)
{
self
.
init
(
keyPath
:
keyPath
.
rawValue
)
self
.
init
(
keyPath
:
keyPath
.
rawValue
)
}
}
}
}
extension
Motion
{
extension
Motion
{
/**
/**
Creates a CABasicAnimation for the opacity key path.
- Parameter opacity: A CGFloat.
- Returns: A CABasicAnimation.
*/
public
static
func
fade
(
opacity
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
opacity
)
animation
.
toValue
=
NSNumber
(
floatLiteral
:
Double
(
opacity
))
return
animation
}
/**
Creates a CABasicAnimation for the backgroundColor key path.
Creates a CABasicAnimation for the backgroundColor key path.
- Parameter color: A UIColor.
- Parameter color: A UIColor.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
background
(
color
:
UIColor
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
background
(
color
:
UIColor
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
backgroundColor
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
backgroundColor
)
animation
.
toValue
=
color
.
cgColor
animation
.
toValue
=
color
.
cgColor
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the cornerRadius key path.
Creates a CABasicAnimation for the cornerRadius key path.
- Parameter radius: A CGFloat.
- Parameter radius: A CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
corner
(
radius
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
corner
(
radius
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
cornerRadius
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
cornerRadius
)
animation
.
toValue
=
radius
animation
.
toValue
=
radius
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform key path.
Creates a CABasicAnimation for the transform key path.
- Parameter transform: A CATransform3D object.
- Parameter transform: A CATransform3D object.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
transform
(
transform
:
CATransform3D
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
transform
(
transform
:
CATransform3D
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
transform
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
transform
)
animation
.
toValue
=
NSValue
(
caTransform3D
:
transform
)
animation
.
toValue
=
NSValue
(
caTransform3D
:
transform
)
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation key path.
Creates a CABasicAnimation for the transform.rotation key path.
- Parameter angle: An optional CGFloat.
- Parameter angle: An optional CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotate
(
angle
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
rotate
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotation
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotation
)
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.x key path.
Creates a CABasicAnimation for the transform.rotation.x key path.
- Parameter angle: An optional CGFloat.
- Parameter angle: An optional CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotateX
(
angle
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
rotateX
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationX
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationX
)
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.y key path.
Creates a CABasicAnimation for the transform.rotation.y key path.
- Parameter angle: An optional CGFloat.
- Parameter angle: An optional CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotateY
(
angle
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
rotateY
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationY
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationY
)
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.z key path.
Creates a CABasicAnimation for the transform.rotation.z key path.
- Parameter angle: An optional CGFloat.
- Parameter angle: An optional CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
rotateZ
(
angle
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
rotateZ
(
angle
:
CGFloat
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationZ
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationZ
)
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
toValue
=
(
CGFloat
(
M_PI
)
*
angle
/
180
)
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation key path.
Creates a CABasicAnimation for the transform.rotation key path.
- Parameter rotations: An optional CGFloat.
- Parameter rotations: An optional CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spin
(
rotations
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
spin
(
rotations
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotation
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotation
)
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.x key path.
Creates a CABasicAnimation for the transform.rotation.x key path.
- Parameter rotations: An optional CGFloat.
- Parameter rotations: An optional CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spinX
(
rotations
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
spinX
(
rotations
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationX
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationX
)
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.y key path.
Creates a CABasicAnimation for the transform.rotation.y key path.
- Parameter rotations: An optional CGFloat.
- Parameter rotations: An optional CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spinY
(
rotations
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
spinY
(
rotations
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationY
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationY
)
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.rotation.z key path.
Creates a CABasicAnimation for the transform.rotation.z key path.
- Parameter rotations: An optional CGFloat.
- Parameter rotations: An optional CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
spinZ
(
rotations
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
spinZ
(
rotations
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationZ
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
rotationZ
)
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
toValue
=
(
CGFloat
(
M_PI
*
2
)
*
rotations
)
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.scale key path.
Creates a CABasicAnimation for the transform.scale key path.
- Parameter by scale: A CGFloat.
- Parameter by scale: A CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
scale
(
by
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
scale
(
by
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scale
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
scale
)
animation
.
toValue
=
scale
as
NSNumber
animation
.
toValue
=
scale
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.scale.x key path.
Creates a CABasicAnimation for the transform.scale.x key path.
- Parameter by scale: A CGFloat.
- Parameter by scale: A CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
scaleX
(
by
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
scaleX
(
by
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleX
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleX
)
animation
.
toValue
=
scale
as
NSNumber
animation
.
toValue
=
scale
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.scale.y key path.
Creates a CABasicAnimation for the transform.scale.y key path.
- Parameter by scale: A CGFloat.
- Parameter by scale: A CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
scaleY
(
by
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
scaleY
(
by
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleY
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleY
)
animation
.
toValue
=
scale
as
NSNumber
animation
.
toValue
=
scale
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.scale.z key path.
Creates a CABasicAnimation for the transform.scale.z key path.
- Parameter by scale: A CGFloat.
- Parameter by scale: A CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
scaleZ
(
by
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
scaleZ
(
by
scale
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleZ
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
scaleZ
)
animation
.
toValue
=
scale
as
NSNumber
animation
.
toValue
=
scale
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.translation key path.
Creates a CABasicAnimation for the transform.translation key path.
- Parameter point: A CGPoint.
- Parameter point: A CGPoint.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
move
(
by
point
:
CGPoint
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
move
(
by
point
:
CGPoint
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
translation
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
translation
)
animation
.
toValue
=
NSValue
(
cgPoint
:
point
)
animation
.
toValue
=
NSValue
(
cgPoint
:
point
)
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
return
animation
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.translation.x key path.
Creates a CABasicAnimation for the transform.translation.x key path.
- Parameter by translation: A CGFloat.
- Parameter by translation: A CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
moveX
(
by
translation
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
moveX
(
by
translation
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
translationX
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
translationX
)
animation
.
toValue
=
translation
as
NSNumber
animation
.
toValue
=
translation
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
return
animation
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.translation.y key path.
Creates a CABasicAnimation for the transform.translation.y key path.
- Parameter by translation: A CGFloat.
- Parameter by translation: A CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
moveY
(
by
translation
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
moveY
(
by
translation
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
translationY
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
translationY
)
animation
.
toValue
=
translation
as
NSNumber
animation
.
toValue
=
translation
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the transform.translation.z key path.
Creates a CABasicAnimation for the transform.translation.z key path.
- Parameter by translation: A CGFloat.
- Parameter by translation: A CGFloat.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
moveZ
(
by
translation
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
moveZ
(
by
translation
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
translationZ
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
translationZ
)
animation
.
toValue
=
translation
as
NSNumber
animation
.
toValue
=
translation
as
NSNumber
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the position key path.
Creates a CABasicAnimation for the position key path.
- Parameter to point: A CGPoint.
- Parameter to point: A CGPoint.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
position
(
to
point
:
CGPoint
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
position
(
to
point
:
CGPoint
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
position
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
position
)
animation
.
toValue
=
NSValue
(
cgPoint
:
point
)
animation
.
toValue
=
NSValue
(
cgPoint
:
point
)
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
easeInEaseOut
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
/**
/**
Creates a CABasicAnimation for the shadowPath key path.
Creates a CABasicAnimation for the shadowPath key path.
- Parameter to path: A CGPath.
- Parameter to path: A CGPath.
- Parameter duration: An animation time duration.
- Returns: A CABasicAnimation.
- Returns: A CABasicAnimation.
*/
*/
public
static
func
shadow
(
path
:
CGPath
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
public
static
func
shadow
(
path
:
CGPath
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowPath
)
let
animation
=
CABasicAnimation
(
keyPath
:
.
shadowPath
)
animation
.
toValue
=
path
animation
.
toValue
=
path
animation
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
animation
.
isRemovedOnCompletion
=
false
animation
.
timingFunction
=
AnimationTimingFunctionToValue
(
function
:
.
linear
)
if
let
v
=
duration
{
animation
.
duration
=
v
}
return
animation
return
animation
}
}
}
}
Sources/iOS/KeyframeMotion.swift
View file @
b9f7bf00
...
@@ -63,7 +63,7 @@ extension Motion {
...
@@ -63,7 +63,7 @@ extension Motion {
*/
*/
public
static
func
path
(
bezierPath
:
UIBezierPath
,
mode
:
AnimationRotationMode
=
.
auto
,
duration
:
CFTimeInterval
?
=
nil
)
->
CAKeyframeAnimation
{
public
static
func
path
(
bezierPath
:
UIBezierPath
,
mode
:
AnimationRotationMode
=
.
auto
,
duration
:
CFTimeInterval
?
=
nil
)
->
CAKeyframeAnimation
{
let
animation
=
CAKeyframeAnimation
()
let
animation
=
CAKeyframeAnimation
()
animation
.
keyPath
=
AnimationKeyPath
.
position
.
rawValue
animation
.
keyPath
=
Motion
AnimationKeyPath
.
position
.
rawValue
animation
.
path
=
bezierPath
.
cgPath
animation
.
path
=
bezierPath
.
cgPath
animation
.
rotationMode
=
AnimationRotationModeToValue
(
mode
:
mode
)
animation
.
rotationMode
=
AnimationRotationModeToValue
(
mode
:
mode
)
...
...
Sources/iOS/PulseMotion.swift
View file @
b9f7bf00
...
@@ -72,7 +72,7 @@ public struct PulseMotion {
...
@@ -72,7 +72,7 @@ public struct PulseMotion {
/// The opcaity value for the pulse animation.
/// The opcaity value for the pulse animation.
public
var
opacity
:
CGFloat
=
0.18
public
var
opacity
:
CGFloat
=
0.18
/**
/**
An initializer that takes a given view and pulse layer.
An initializer that takes a given view and pulse layer.
- Parameter pulseView: An optional UIView.
- Parameter pulseView: An optional UIView.
...
@@ -113,7 +113,7 @@ extension PulseMotion {
...
@@ -113,7 +113,7 @@ extension PulseMotion {
layers
.
insert
(
bLayer
,
at
:
0
)
layers
.
insert
(
bLayer
,
at
:
0
)
layer
.
masksToBounds
=
!
(
.
centerRadialBeyondBounds
==
animation
||
.
radialBeyondBounds
==
animation
)
layer
.
masksToBounds
=
!
(
.
centerRadialBeyondBounds
==
animation
||
.
radialBeyondBounds
==
animation
)
let
w
=
view
.
bounds
.
width
let
w
=
view
.
bounds
.
width
let
h
=
view
.
bounds
.
height
let
h
=
view
.
bounds
.
height
...
@@ -146,24 +146,24 @@ extension PulseMotion {
...
@@ -146,24 +146,24 @@ extension PulseMotion {
switch
animation
{
switch
animation
{
case
.
centerWithBacking
,
.
backing
,
.
pointWithBacking
,
.
tap
:
case
.
centerWithBacking
,
.
backing
,
.
pointWithBacking
,
.
tap
:
bLayer
.
add
(
Motion
.
background
(
color
:
color
.
withAlphaComponent
(
opacity
/
2
),
duration
:
duration
),
forKey
:
nil
)
bLayer
.
motion
(
duration
:
duration
,
animations
:
.
background
(
color
:
color
.
withAlphaComponent
(
opacity
/
2
))
)
default
:
break
default
:
break
}
}
switch
animation
{
switch
animation
{
case
.
center
,
.
centerWithBacking
,
.
centerRadialBeyondBounds
,
.
radialBeyondBounds
,
.
point
,
.
pointWithBacking
:
case
.
center
,
.
centerWithBacking
,
.
centerRadialBeyondBounds
,
.
radialBeyondBounds
,
.
point
,
.
pointWithBacking
:
pLayer
.
add
(
Motion
.
scale
(
by
:
1
,
duration
:
duration
),
forKey
:
nil
)
pLayer
.
motion
(
duration
:
duration
,
animations
:
.
scale
(
by
:
1
)
)
default
:
break
default
:
break
}
}
Motion
.
delay
(
time
:
duration
)
{
Motion
.
delay
(
time
:
duration
)
{
bLayer
.
setValue
(
true
,
forKey
:
"animated"
)
bLayer
.
setValue
(
true
,
forKey
:
"animated"
)
}
}
}
}
}
}
extension
PulseMotion
{
extension
PulseMotion
{
/// Triggers the contracting animation.
/// Triggers the contracting animation.
public
mutating
func
contract
()
{
public
mutating
func
contract
()
{
guard
let
bLayer
=
layers
.
popLast
()
else
{
guard
let
bLayer
=
layers
.
popLast
()
else
{
return
return
...
@@ -182,16 +182,13 @@ extension PulseMotion {
...
@@ -182,16 +182,13 @@ extension PulseMotion {
switch
animation
{
switch
animation
{
case
.
centerWithBacking
,
.
backing
,
.
pointWithBacking
,
.
tap
:
case
.
centerWithBacking
,
.
backing
,
.
pointWithBacking
,
.
tap
:
bLayer
.
add
(
Motion
.
background
(
color
:
color
.
withAlphaComponent
(
0
),
duration
:
duration
),
forKey
:
nil
)
bLayer
.
motion
(
duration
:
duration
,
animations
:
.
background
(
color
:
color
.
withAlphaComponent
(
0
))
)
default
:
break
default
:
break
}
}
switch
animation
{
switch
animation
{
case
.
center
,
.
centerWithBacking
,
.
centerRadialBeyondBounds
,
.
radialBeyondBounds
,
.
point
,
.
pointWithBacking
:
case
.
center
,
.
centerWithBacking
,
.
centerRadialBeyondBounds
,
.
radialBeyondBounds
,
.
point
,
.
pointWithBacking
:
pLayer
.
add
(
Motion
.
animate
(
group
:
[
pLayer
.
motion
(
duration
:
duration
,
animations
:
.
scale
(
by
:
.
center
==
animation
?
1
:
1.325
),
.
background
(
color
:
color
.
withAlphaComponent
(
0
)))
Motion
.
scale
(
by
:
.
center
==
animation
?
1
:
1.325
),
Motion
.
background
(
color
:
color
.
withAlphaComponent
(
0
))
],
duration
:
duration
),
forKey
:
nil
)
default
:
break
default
:
break
}
}
...
@@ -200,5 +197,5 @@ extension PulseMotion {
...
@@ -200,5 +197,5 @@ extension PulseMotion {
bLayer
.
removeFromSuperlayer
()
bLayer
.
removeFromSuperlayer
()
}
}
}
}
}
}
}
}
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