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