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
486cab29
Unverified
Commit
486cab29
authored
Oct 25, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
development: refactors Animation class
parent
c97e64b6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
117 additions
and
82 deletions
+117
-82
Sources/iOS/Animation.swift
+49
-28
Sources/iOS/BasicAnimation.swift
+0
-0
Sources/iOS/Capture/Capture.swift
+2
-2
Sources/iOS/KeyframeAnimation.swift
+16
-10
Sources/iOS/Material+CALayer.swift
+1
-1
Sources/iOS/PulseAnimation.swift
+4
-4
Sources/iOS/TransitionAnimation.swift
+45
-37
No files found.
Sources/iOS/Animation.swift
View file @
486cab29
...
@@ -57,20 +57,21 @@ public func AnimationFillModeToValue(mode: AnimationFillMode) -> String {
...
@@ -57,20 +57,21 @@ public func AnimationFillModeToValue(mode: AnimationFillMode) -> String {
@objc(AnimationTimingFunction)
@objc(AnimationTimingFunction)
public
enum
AnimationTimingFunction
:
Int
{
public
enum
AnimationTimingFunction
:
Int
{
case
liner
case
line
a
r
case
easeIn
case
easeIn
case
easeOut
case
easeOut
case
easeInEaseOut
case
easeInEaseOut
case
systemDefault
case
`
default
`
}
}
/**
/**
Converts the AnimationTimingFunction enum value to a corresponding CAMediaTimingFunction.
Converts the AnimationTimingFunction enum value to a corresponding CAMediaTimingFunction.
- Parameter function: An AnimationTimingFunction enum value.
- Parameter function: An AnimationTimingFunction enum value.
- Returns: A CAMediaTimingFunction.
*/
*/
public
func
AnimationTimingFunctionToValue
(
function
:
AnimationTimingFunction
)
->
CAMediaTimingFunction
{
public
func
AnimationTimingFunctionToValue
(
function
:
AnimationTimingFunction
)
->
CAMediaTimingFunction
{
switch
function
{
switch
function
{
case
.
liner
:
case
.
line
a
r
:
return
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionLinear
)
return
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionLinear
)
case
.
easeIn
:
case
.
easeIn
:
return
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseIn
)
return
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseIn
)
...
@@ -78,18 +79,23 @@ public func AnimationTimingFunctionToValue(function: AnimationTimingFunction) ->
...
@@ -78,18 +79,23 @@ public func AnimationTimingFunctionToValue(function: AnimationTimingFunction) ->
return
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseOut
)
return
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseOut
)
case
.
easeInEaseOut
:
case
.
easeInEaseOut
:
return
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseInEaseOut
)
return
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionEaseInEaseOut
)
case
.
systemD
efault
:
case
.
d
efault
:
return
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionDefault
)
return
CAMediaTimingFunction
(
name
:
kCAMediaTimingFunctionDefault
)
}
}
}
}
public
typealias
AnimationDelayCancelBlock
=
(
Bool
)
->
Void
public
typealias
AnimationDelayCancelBlock
=
(
Bool
)
->
Void
public
struct
Animation
{
public
struct
Animation
{
/// Delay helper method.
/**
Executes a block of code after a time delay.
- Parameter duration: An animation duration time.
- Parameter animations: An animation block.
- Parameter execute block: A completion block that is executed once
the animations have completed.
*/
@discardableResult
@discardableResult
public
static
func
delay
(
time
:
TimeInterval
,
completion
:
@escaping
()
->
Void
)
->
AnimationDelayCancelBlock
?
{
public
static
func
delay
(
time
:
TimeInterval
,
execute
block
:
@escaping
()
->
Void
)
->
AnimationDelayCancelBlock
?
{
func
asyncAfter
(
completion
:
@escaping
()
->
Void
)
{
func
asyncAfter
(
completion
:
@escaping
()
->
Void
)
{
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
DispatchTime
.
now
()
+
time
,
execute
:
completion
)
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
DispatchTime
.
now
()
+
time
,
execute
:
completion
)
...
@@ -97,10 +103,11 @@ public struct Animation {
...
@@ -97,10 +103,11 @@ public struct Animation {
var
cancelable
:
AnimationDelayCancelBlock
?
var
cancelable
:
AnimationDelayCancelBlock
?
let
delayed
:
AnimationDelayCancelBlock
=
{
(
cancel
)
in
let
delayed
:
AnimationDelayCancelBlock
=
{
if
!
cancel
{
if
!
$0
{
DispatchQueue
.
main
.
async
(
execute
:
completion
)
DispatchQueue
.
main
.
async
(
execute
:
block
)
}
}
cancelable
=
nil
cancelable
=
nil
}
}
...
@@ -114,24 +121,30 @@ public struct Animation {
...
@@ -114,24 +121,30 @@ public struct Animation {
}
}
/**
/**
:name: delayCancel
Cancels the delayed AnimationDelayCancelBlock.
*/
- Parameter delayed completion: An AnimationDelayCancelBlock.
public
static
func
delayCancel
(
completion
:
AnimationDelayCancelBlock
)
{
*/
public
static
func
cancel
(
delayed
completion
:
AnimationDelayCancelBlock
)
{
completion
(
true
)
completion
(
true
)
}
}
/**
/**
:name: animationDisabled
Disables the default animations set on CALayers.
*/
- Parameter animations: A callback that wraps the animations to disable.
public
static
func
animationDisabled
(
animations
:
(()
->
Void
))
{
*/
animateWithDuration
(
duration
:
0
,
animations
:
animations
)
public
static
func
disable
(
animations
:
(()
->
Void
))
{
animate
(
duration
:
0
,
animations
:
animations
)
}
}
/**
/**
:name: animateWithDuration
Runs an animation with a specified duration.
*/
- Parameter duration: An animation duration time.
public
static
func
animateWithDuration
(
duration
:
CFTimeInterval
,
animations
:
(()
->
Void
),
completion
:
(()
->
Void
)?
=
nil
)
{
- Parameter animations: An animation block.
- Parameter completion: A completion block that is executed once
the animations have completed.
*/
public
static
func
animate
(
duration
:
CFTimeInterval
,
animations
:
(()
->
Void
),
completion
:
(()
->
Void
)?
=
nil
)
{
CATransaction
.
begin
()
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
duration
)
CATransaction
.
setAnimationDuration
(
duration
)
CATransaction
.
setCompletionBlock
(
completion
)
CATransaction
.
setCompletionBlock
(
completion
)
...
@@ -141,9 +154,12 @@ public struct Animation {
...
@@ -141,9 +154,12 @@ public struct Animation {
}
}
/**
/**
:name: animationGroup
Creates a CAAnimationGroup.
*/
- Parameter animations: An Array of CAAnimation objects.
public
static
func
animationGroup
(
animations
:
[
CAAnimation
],
duration
:
CFTimeInterval
=
0.5
)
->
CAAnimationGroup
{
- Parameter duration: An animation duration time for the group.
- Returns: A CAAnimationGroup.
*/
public
static
func
animate
(
group
animations
:
[
CAAnimation
],
duration
:
CFTimeInterval
=
0.5
)
->
CAAnimationGroup
{
let
group
:
CAAnimationGroup
=
CAAnimationGroup
()
let
group
:
CAAnimationGroup
=
CAAnimationGroup
()
group
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
group
.
fillMode
=
AnimationFillModeToValue
(
mode
:
.
forwards
)
group
.
isRemovedOnCompletion
=
false
group
.
isRemovedOnCompletion
=
false
...
@@ -154,11 +170,16 @@ public struct Animation {
...
@@ -154,11 +170,16 @@ public struct Animation {
}
}
/**
/**
:name: animateWithDelay
Executes an animation block with a given delay and duration.
*/
- Parameter delay time: A CFTimeInterval.
public
static
func
animateWithDelay
(
delay
d
:
CFTimeInterval
,
duration
:
CFTimeInterval
,
animations
:
@escaping
(()
->
Void
),
completion
:
(()
->
Void
)?
=
nil
)
{
- Parameter duration: An animation duration time.
delay
(
time
:
d
)
{
- Parameter animations: An animation block.
animateWithDuration
(
duration
:
duration
,
animations
:
animations
,
completion
:
completion
)
- Parameter completion: A completion block that is executed once
the animations have completed.
*/
public
static
func
animate
(
delay
time
:
CFTimeInterval
,
duration
:
CFTimeInterval
,
animations
:
@escaping
(()
->
Void
),
completion
:
(()
->
Void
)?
=
nil
)
{
delay
(
time
:
time
)
{
animate
(
duration
:
duration
,
animations
:
animations
,
completion
:
completion
)
}
}
}
}
}
}
Sources/iOS/BasicAnimation.swift
View file @
486cab29
This diff is collapsed.
Click to expand it.
Sources/iOS/Capture/Capture.swift
View file @
486cab29
...
@@ -629,7 +629,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
...
@@ -629,7 +629,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
/// Animates the tap and layer.
/// Animates the tap and layer.
private
func
animateTap
(
view
:
UIView
,
point
:
CGPoint
)
{
private
func
animateTap
(
view
:
UIView
,
point
:
CGPoint
)
{
// Animation.
animationDisabled
{ [weak layer] in
// Animation.
disable
{ [weak layer] in
// guard let v = layer else {
// guard let v = layer else {
// return
// return
// }
// }
...
@@ -644,7 +644,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
...
@@ -644,7 +644,7 @@ open class Capture: View, UIGestureRecognizerDelegate {
// v.transform = CATransform3DMakeScale(0.5, 0.5, 1)
// v.transform = CATransform3DMakeScale(0.5, 0.5, 1)
// }) {
// }) {
// Animation.delay(time: 0.4) { [weak layer] in
// Animation.delay(time: 0.4) { [weak layer] in
// Animation.
animationDisabled
{ [weak layer] in
// Animation.
disable
{ [weak layer] in
// guard let v = layer else {
// guard let v = layer else {
// return
// return
// }
// }
...
...
Sources/iOS/KeyframeAnimation.swift
View file @
486cab29
...
@@ -32,19 +32,21 @@ import UIKit
...
@@ -32,19 +32,21 @@ import UIKit
@objc(AnimationRotationMode)
@objc(AnimationRotationMode)
public
enum
AnimationRotationMode
:
Int
{
public
enum
AnimationRotationMode
:
Int
{
case
none
case
`
default
`
case
auto
case
auto
case
autoReverse
case
autoReverse
}
}
/**
/**
:name: AnimationRotationModeToValue
Converts an AnimationRotationMode to a corresponding CAAnimationRotate key.
*/
- Parameter mode: An AnimationRotationMode.
- Returns: An optional CAAnimationRotate key String.
*/
public
func
AnimationRotationModeToValue
(
mode
:
AnimationRotationMode
)
->
String
?
{
public
func
AnimationRotationModeToValue
(
mode
:
AnimationRotationMode
)
->
String
?
{
switch
mode
{
switch
mode
{
case
.
none
:
case
.
default
:
return
nil
return
nil
case
.
auto
:
case
.
auto
:
return
kCAAnimationRotateAuto
return
kCAAnimationRotateAuto
case
.
autoReverse
:
case
.
autoReverse
:
return
kCAAnimationRotateAutoReverse
return
kCAAnimationRotateAutoReverse
...
@@ -53,11 +55,15 @@ public func AnimationRotationModeToValue(mode: AnimationRotationMode) -> String?
...
@@ -53,11 +55,15 @@ public func AnimationRotationModeToValue(mode: AnimationRotationMode) -> String?
extension
Animation
{
extension
Animation
{
/**
/**
:name: path
Creates a CAKeyframeAnimation.
*/
- Parameter bezierPath: A UIBezierPath.
- Parameter mode: An AnimationRotationMode.
- Parameter duration: An animation duration time.
- Returns: A CAKeyframeAnimation.
*/
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
=
CAKeyframeAnimation
()
let
animation
=
CAKeyframeAnimation
()
animation
.
keyPath
=
AnimationKey
.
position
.
rawValue
animation
.
keyPath
=
AnimationKey
Path
.
position
.
rawValue
animation
.
path
=
bezierPath
.
cgPath
animation
.
path
=
bezierPath
.
cgPath
animation
.
rotationMode
=
AnimationRotationModeToValue
(
mode
:
mode
)
animation
.
rotationMode
=
AnimationRotationModeToValue
(
mode
:
mode
)
if
let
v
=
duration
{
if
let
v
=
duration
{
...
...
Sources/iOS/Material+CALayer.swift
View file @
486cab29
...
@@ -321,7 +321,7 @@ extension CALayer {
...
@@ -321,7 +321,7 @@ extension CALayer {
}
else
if
nil
==
shadowPath
{
}
else
if
nil
==
shadowPath
{
shadowPath
=
UIBezierPath
(
roundedRect
:
bounds
,
cornerRadius
:
cornerRadius
)
.
cgPath
shadowPath
=
UIBezierPath
(
roundedRect
:
bounds
,
cornerRadius
:
cornerRadius
)
.
cgPath
}
else
{
}
else
{
let
a
=
Animation
.
shadowPath
(
path
:
UIBezierPath
(
roundedRect
:
bounds
,
cornerRadius
:
cornerRadius
)
.
cgPath
)
let
a
=
Animation
.
shadowPath
(
to
:
UIBezierPath
(
roundedRect
:
bounds
,
cornerRadius
:
cornerRadius
)
.
cgPath
)
a
.
fromValue
=
shadowPath
a
.
fromValue
=
shadowPath
animate
(
animation
:
a
)
animate
(
animation
:
a
)
}
}
...
...
Sources/iOS/PulseAnimation.swift
View file @
486cab29
...
@@ -71,7 +71,7 @@ internal extension Animation {
...
@@ -71,7 +71,7 @@ internal extension Animation {
visualLayer
.
masksToBounds
=
!
(
.
centerRadialBeyondBounds
==
pulse
.
animation
||
.
radialBeyondBounds
==
pulse
.
animation
)
visualLayer
.
masksToBounds
=
!
(
.
centerRadialBeyondBounds
==
pulse
.
animation
||
.
radialBeyondBounds
==
pulse
.
animation
)
Animation
.
animationDisabled
(
animations
:
{
[
visualLayer
=
visualLayer
,
pulse
=
pulse
]
in
Animation
.
disable
(
animations
:
{
[
visualLayer
=
visualLayer
,
pulse
=
pulse
]
in
bLayer
.
frame
=
visualLayer
.
bounds
bLayer
.
frame
=
visualLayer
.
bounds
pLayer
.
bounds
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
n
,
height
:
n
)
pLayer
.
bounds
=
CGRect
(
x
:
0
,
y
:
0
,
width
:
n
,
height
:
n
)
...
@@ -99,7 +99,7 @@ internal extension Animation {
...
@@ -99,7 +99,7 @@ internal extension Animation {
switch
pulse
.
animation
{
switch
pulse
.
animation
{
case
.
center
,
.
centerWithBacking
,
.
centerRadialBeyondBounds
,
.
radialBeyondBounds
,
.
point
,
.
pointWithBacking
:
case
.
center
,
.
centerWithBacking
,
.
centerRadialBeyondBounds
,
.
radialBeyondBounds
,
.
point
,
.
pointWithBacking
:
pLayer
.
add
(
Animation
.
scale
(
scale
:
1
,
duration
:
duration
),
forKey
:
nil
)
pLayer
.
add
(
Animation
.
scale
(
by
:
1
,
duration
:
duration
),
forKey
:
nil
)
default
:
break
default
:
break
}
}
...
@@ -138,8 +138,8 @@ internal extension Animation {
...
@@ -138,8 +138,8 @@ internal extension Animation {
switch
pulse
.
animation
{
switch
pulse
.
animation
{
case
.
center
,
.
centerWithBacking
,
.
centerRadialBeyondBounds
,
.
radialBeyondBounds
,
.
point
,
.
pointWithBacking
:
case
.
center
,
.
centerWithBacking
,
.
centerRadialBeyondBounds
,
.
radialBeyondBounds
,
.
point
,
.
pointWithBacking
:
pLayer
.
add
(
Animation
.
animat
ionGroup
(
animations
:
[
pLayer
.
add
(
Animation
.
animat
e
(
group
:
[
Animation
.
scale
(
scale
:
.
center
==
pulse
.
animation
?
1
:
1.325
),
Animation
.
scale
(
by
:
.
center
==
pulse
.
animation
?
1
:
1.325
),
Animation
.
backgroundColor
(
color
:
pulse
.
color
.
withAlphaComponent
(
0
))
Animation
.
backgroundColor
(
color
:
pulse
.
color
.
withAlphaComponent
(
0
))
],
duration
:
duration
),
forKey
:
nil
)
],
duration
:
duration
),
forKey
:
nil
)
default
:
break
default
:
break
...
...
Sources/iOS/TransitionAnimation.swift
View file @
486cab29
...
@@ -30,70 +30,78 @@
...
@@ -30,70 +30,78 @@
import
UIKit
import
UIKit
public
typealias
AnimationTransitionType
=
String
public
typealias
AnimationTransitionSubTypeType
=
String
@objc(AnimationTransition)
@objc(AnimationTransition)
public
enum
AnimationTransition
:
Int
{
public
enum
AnimationTransition
:
Int
{
case
F
ade
case
f
ade
case
M
oveIn
case
m
oveIn
case
P
ush
case
p
ush
case
R
eveal
case
r
eveal
}
}
@objc(AnimationTransitionSubType)
@objc(AnimationTransitionDirection)
public
enum
AnimationTransitionSubType
:
Int
{
public
enum
AnimationTransitionDirection
:
Int
{
case
Right
case
`
default
`
case
Left
case
right
case
Top
case
left
case
Bottom
case
top
case
bottom
}
}
/**
/**
:name: AnimationTransitionToValue
Converts an AnimationTransition to a corresponding CATransition key.
*/
- Parameter transition: An AnimationTransition.
public
func
AnimationTransitionToValue
(
transition
:
AnimationTransition
)
->
AnimationTransitionType
{
- Returns: A CATransition key String.
switch
transition
{
*/
case
.
Fade
:
public
func
AnimationTransitionToValue
(
transition
type
:
AnimationTransition
)
->
String
{
switch
type
{
case
.
fade
:
return
kCATransitionFade
return
kCATransitionFade
case
.
M
oveIn
:
case
.
m
oveIn
:
return
kCATransitionMoveIn
return
kCATransitionMoveIn
case
.
P
ush
:
case
.
p
ush
:
return
kCATransitionPush
return
kCATransitionPush
case
.
R
eveal
:
case
.
r
eveal
:
return
kCATransitionReveal
return
kCATransitionReveal
}
}
}
}
/**
/**
:name: AnimationTransitionSubTypeToValue
Converts an AnimationTransitionDirection to a corresponding CATransition direction key.
*/
- Parameter direction: An AnimationTransitionDirection.
public
func
AnimationTransitionSubTypeToValue
(
direction
:
AnimationTransitionSubType
)
->
AnimationTransitionSubTypeType
{
- Returns: An optional CATransition direction key String.
*/
public
func
AnimationTransitionDirectionToValue
(
direction
:
AnimationTransitionDirection
)
->
String
?
{
switch
direction
{
switch
direction
{
case
.
Right
:
case
.
default
:
return
nil
case
.
right
:
return
kCATransitionFromRight
return
kCATransitionFromRight
case
.
L
eft
:
case
.
l
eft
:
return
kCATransitionFromLeft
return
kCATransitionFromLeft
case
.
T
op
:
case
.
t
op
:
return
kCATransitionFromBottom
return
kCATransitionFromBottom
case
.
B
ottom
:
case
.
b
ottom
:
return
kCATransitionFromTop
return
kCATransitionFromTop
}
}
}
}
extension
Animation
{
extension
Animation
{
/**
/**
:name: transition
Creates a CATransition animation.
*/
- Parameter type: An AnimationTransition.
public
static
func
transition
(
type
:
AnimationTransition
,
direction
:
AnimationTransitionSubType
?
=
nil
,
duration
:
CFTimeInterval
?
=
nil
)
->
CATransition
{
- Parameter direction: An optional AnimationTransitionDirection.
let
animation
:
CATransition
=
CATransition
()
- Parameter duration: An optional duration time.
- Returns: A CATransition.
*/
public
static
func
transition
(
type
:
AnimationTransition
,
direction
:
AnimationTransitionDirection
=
.
default
,
duration
:
CFTimeInterval
?
=
nil
)
->
CATransition
{
let
animation
=
CATransition
()
animation
.
type
=
AnimationTransitionToValue
(
transition
:
type
)
animation
.
type
=
AnimationTransitionToValue
(
transition
:
type
)
if
let
d
=
direction
{
animation
.
subtype
=
AnimationTransitionDirectionToValue
(
direction
:
direction
)
animation
.
subtype
=
AnimationTransitionSubTypeToValue
(
direction
:
d
)
}
if
let
v
=
duration
{
if
let
v
:
CFTimeInterval
=
duration
{
animation
.
duration
=
v
animation
.
duration
=
v
}
}
return
animation
return
animation
}
}
}
}
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