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
55f9e5a3
Commit
55f9e5a3
authored
Oct 03, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleaned animation in MaterialView additions
parent
9e0f67a1
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
103 deletions
+87
-103
Source/MaterialAnimation.swift
+29
-28
Source/MaterialBasicAnimation.swift
+20
-51
Source/MaterialKeyframeAnimation.swift
+3
-10
Source/MaterialPulseView.swift
+18
-4
Source/MaterialView.swift
+17
-10
No files found.
Source/MaterialAnimation.swift
View file @
55f9e5a3
...
@@ -18,6 +18,31 @@
...
@@ -18,6 +18,31 @@
import
UIKit
import
UIKit
public
typealias
MaterialAnimationFillModeType
=
String
public
enum
MaterialAnimationFillMode
{
case
Forwards
case
Backwards
case
Both
case
Removed
}
/**
:name: MaterialAnimationFillModeToValue
*/
public
func
MaterialAnimationFillModeToValue
(
mode
:
MaterialAnimationFillMode
)
->
MaterialAnimationFillModeType
{
switch
mode
{
case
.
Forwards
:
return
kCAFillModeForwards
case
.
Backwards
:
return
kCAFillModeBackwards
case
.
Both
:
return
kCAFillModeBoth
case
.
Removed
:
return
kCAFillModeRemoved
}
}
public
struct
MaterialAnimation
{
public
struct
MaterialAnimation
{
/**
/**
:name: disableAnimation
:name: disableAnimation
...
@@ -32,36 +57,12 @@ public struct MaterialAnimation {
...
@@ -32,36 +57,12 @@ public struct MaterialAnimation {
/**
/**
:name: groupAnimation
:name: groupAnimation
*/
*/
public
static
func
groupAnimation
(
view
:
UIView
,
animations
:
Array
<
CAAnimation
>
,
duration
:
NSTimeInterval
=
0.5
)
{
public
static
func
groupAnimation
(
animations
:
Array
<
CAAnimation
>
,
duration
:
NSTimeInterval
=
0.5
)
->
CAAnimationGroup
{
groupAnimation
(
view
.
layer
,
animations
:
animations
,
duration
:
duration
)
}
/**
:name: groupAnimation
*/
public
static
func
groupAnimation
(
layer
:
CALayer
,
animations
:
Array
<
CAAnimation
>
,
duration
:
NSTimeInterval
=
0.5
)
{
let
group
:
CAAnimationGroup
=
CAAnimationGroup
()
let
group
:
CAAnimationGroup
=
CAAnimationGroup
()
group
.
fillMode
=
MaterialAnimationFillModeToValue
(
.
Forwards
)
group
.
removedOnCompletion
=
false
group
.
animations
=
animations
group
.
animations
=
animations
group
.
duration
=
duration
group
.
duration
=
duration
layer
.
addAnimation
(
group
,
forKey
:
nil
)
return
group
}
/**
:name: applyBasicAnimation
*/
internal
static
func
applyBasicAnimation
(
animation
:
CABasicAnimation
,
toLayer
layer
:
CALayer
)
{
// groupAnimation(layer, animations: [animation], duration: animation.duration)
// CATransaction.begin()
// CATransaction.setAnimationDuration(animation.duration)
// layer.setValue(nil == animation.toValue ? animation.byValue : animation.toValue, forKey: animation.keyPath!)
// CATransaction.commit()
}
/**
:name: applyKeyframeAnimation
*/
internal
static
func
applyKeyframeAnimation
(
animation
:
CAKeyframeAnimation
,
toLayer
layer
:
CALayer
)
{
// use presentation layer if available
(
nil
==
layer
.
presentationLayer
()
?
layer
:
layer
.
presentationLayer
()
as!
CALayer
)
.
addAnimation
(
animation
,
forKey
:
animation
.
keyPath
!
)
}
}
}
}
Source/MaterialBasicAnimation.swift
View file @
55f9e5a3
...
@@ -20,97 +20,67 @@ import UIKit
...
@@ -20,97 +20,67 @@ import UIKit
public
extension
MaterialAnimation
{
public
extension
MaterialAnimation
{
/**
/**
:name: backgroundColor
Animation
:name: backgroundColor
*/
*/
public
static
func
backgroundColor
Animation
(
color
:
UIColor
)
->
CABasicAnimation
{
public
static
func
backgroundColor
(
color
:
UIColor
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"backgroundColor"
animation
.
keyPath
=
"backgroundColor"
animation
.
toValue
=
color
.
CGColor
animation
.
toValue
=
color
.
CGColor
return
animation
if
let
d
=
duration
{
animation
.
duration
=
d
}
}
/**
:name: backgroundColor
*/
public
static
func
backgroundColor
(
color
:
UIColor
,
duration
:
CFTimeInterval
=
0.25
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
backgroundColorAnimation
(
color
)
animation
.
duration
=
duration
return
animation
return
animation
}
}
/**
/**
:name: cornerRadius
Animation
:name: cornerRadius
*/
*/
public
static
func
cornerRadius
Animation
(
radius
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
cornerRadius
(
radius
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"cornerRadius"
animation
.
keyPath
=
"cornerRadius"
animation
.
toValue
=
radius
animation
.
toValue
=
radius
return
animation
if
let
d
=
duration
{
animation
.
duration
=
d
}
}
/**
:name: cornerRadius
*/
public
static
func
cornerRadius
(
radius
:
CGFloat
,
duration
:
CFTimeInterval
=
0.25
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
cornerRadiusAnimation
(
radius
)
animation
.
duration
=
duration
return
animation
return
animation
}
}
/**
/**
:name: rotation
Animation
:name: rotation
*/
*/
public
static
func
rotation
Animation
(
rotations
:
Int
=
1
)
->
CABasicAnimation
{
public
static
func
rotation
(
rotations
:
Int
=
1
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform.rotation"
animation
.
keyPath
=
"transform.rotation"
animation
.
byValue
=
M_PI
*
2
*
Double
(
rotations
)
animation
.
byValue
=
M_PI
*
2
*
Double
(
rotations
)
return
animation
if
let
d
=
duration
{
animation
.
duration
=
d
}
}
/**
:name: rotation
*/
public
static
func
rotation
(
rotations
:
Int
=
1
,
duration
:
CFTimeInterval
=
0.5
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
rotationAnimation
(
rotations
)
animation
.
duration
=
duration
return
animation
return
animation
}
}
/**
/**
:name: scale
Animation
:name: scale
*/
*/
public
static
func
scale
Animation
(
transform
:
CATransform3D
)
->
CABasicAnimation
{
public
static
func
scale
(
transform
:
CATransform3D
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform"
animation
.
keyPath
=
"transform"
animation
.
toValue
=
NSValue
(
CATransform3D
:
transform
)
animation
.
toValue
=
NSValue
(
CATransform3D
:
transform
)
return
animation
if
let
d
=
duration
{
animation
.
duration
=
d
}
}
/**
:name: scale
*/
public
static
func
scale
(
transform
:
CATransform3D
,
duration
:
CFTimeInterval
=
0.25
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
scaleAnimation
(
transform
)
animation
.
duration
=
duration
return
animation
return
animation
}
}
/**
/**
:name: position
Animation
:name: position
*/
*/
public
static
func
position
Animation
(
point
:
CGPoint
)
->
CABasicAnimation
{
public
static
func
position
(
point
:
CGPoint
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"position"
animation
.
keyPath
=
"position"
animation
.
toValue
=
NSValue
(
CGPoint
:
point
)
animation
.
toValue
=
NSValue
(
CGPoint
:
point
)
return
animation
if
let
d
=
duration
{
animation
.
duration
=
d
}
}
/**
:name: position
*/
public
static
func
position
(
point
:
CGPoint
,
duration
:
CFTimeInterval
=
0.5
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
positionAnimation
(
point
)
animation
.
duration
=
duration
return
animation
return
animation
}
}
}
}
\ No newline at end of file
Source/MaterialKeyframeAnimation.swift
View file @
55f9e5a3
...
@@ -44,20 +44,14 @@ public extension MaterialAnimation {
...
@@ -44,20 +44,14 @@ public extension MaterialAnimation {
/**
/**
:name: path
:name: path
*/
*/
public
static
func
path
Animation
(
bezierPath
:
UIBezierPath
,
mode
:
MaterialAnimationRotationMode
=
.
Auto
)
->
CAKeyframeAnimation
{
public
static
func
path
(
bezierPath
:
UIBezierPath
,
duration
:
CFTimeInterval
?
,
mode
:
MaterialAnimationRotationMode
=
.
Auto
)
->
CAKeyframeAnimation
{
let
animation
:
CAKeyframeAnimation
=
CAKeyframeAnimation
()
let
animation
:
CAKeyframeAnimation
=
CAKeyframeAnimation
()
animation
.
keyPath
=
"position"
animation
.
keyPath
=
"position"
animation
.
path
=
bezierPath
.
CGPath
animation
.
path
=
bezierPath
.
CGPath
animation
.
rotationMode
=
MaterialAnimationRotationModeToValue
(
mode
)
animation
.
rotationMode
=
MaterialAnimationRotationModeToValue
(
mode
)
return
animation
if
let
d
=
duration
{
animation
.
duration
=
d
}
}
/**
:name: path
*/
public
static
func
path
(
bezierPath
:
UIBezierPath
,
mode
:
MaterialAnimationRotationMode
=
.
Auto
,
duration
:
CFTimeInterval
=
1
)
->
CAKeyframeAnimation
{
let
animation
:
CAKeyframeAnimation
=
pathAnimation
(
bezierPath
,
mode
:
mode
)
animation
.
duration
=
duration
return
animation
return
animation
}
}
}
}
\ No newline at end of file
Source/MaterialPulseView.swift
View file @
55f9e5a3
...
@@ -64,12 +64,12 @@ public class MaterialPulseView : MaterialView {
...
@@ -64,12 +64,12 @@ public class MaterialPulseView : MaterialView {
public
override
func
touchesBegan
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
public
override
func
touchesBegan
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
let
point
:
CGPoint
=
touches
.
first
!.
locationInView
(
self
)
let
point
:
CGPoint
=
touches
.
first
!.
locationInView
(
self
)
let
w
:
CGFloat
=
(
width
<
height
?
height
:
width
)
/
2
let
s
:
CGFloat
=
(
width
<
height
?
height
:
width
)
/
2
MaterialAnimation
.
disableAnimation
({
_
in
MaterialAnimation
.
disableAnimation
({
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
w
,
w
)
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
s
,
s
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
self
.
pulseLayer
.
cornerRadius
=
s
/
2
})
})
pulseLayer
.
hidden
=
false
pulseLayer
.
hidden
=
false
...
@@ -100,6 +100,20 @@ public class MaterialPulseView : MaterialView {
...
@@ -100,6 +100,20 @@ public class MaterialPulseView : MaterialView {
return
nil
// returning nil enables the animations for the layer property that are normally disabled.
return
nil
// returning nil enables the animations for the layer property that are normally disabled.
}
}
/**
:name: addAnimation
*/
public
override
func
addAnimation
(
animation
:
CAAnimation
)
{
super
.
addAnimation
(
animation
)
if
let
a
=
animation
as?
CABasicAnimation
{
touchesLayer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
=
animation
as?
CAKeyframeAnimation
{
touchesLayer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
=
animation
as?
CAAnimationGroup
{
touchesLayer
.
addAnimation
(
a
,
forKey
:
nil
)
}
}
//
//
// :name: prepareView
// :name: prepareView
//
//
...
...
Source/MaterialView.swift
View file @
55f9e5a3
...
@@ -305,31 +305,38 @@ public class MaterialView : UIView {
...
@@ -305,31 +305,38 @@ public class MaterialView : UIView {
if
let
a
=
animation
as?
CABasicAnimation
{
if
let
a
=
animation
as?
CABasicAnimation
{
a
.
fromValue
=
(
nil
==
layer
.
presentationLayer
()
?
layer
:
layer
.
presentationLayer
()
as!
CALayer
)
.
valueForKeyPath
(
a
.
keyPath
!
)
a
.
fromValue
=
(
nil
==
layer
.
presentationLayer
()
?
layer
:
layer
.
presentationLayer
()
as!
CALayer
)
.
valueForKeyPath
(
a
.
keyPath
!
)
a
.
delegate
=
self
a
.
delegate
=
self
a
.
fillMode
=
kCAFillModeForwards
layer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
a
.
removedOnCompletion
=
false
visualLayer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
layer
.
addAnimation
(
animation
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
=
animation
as?
CAKeyframeAnimation
{
}
else
if
let
a
=
animation
as?
CAKeyframeAnimation
{
a
.
delegate
=
self
a
.
delegate
=
self
a
.
fillMode
=
kCAFillModeForwards
layer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
a
.
removedOnCompletion
=
false
visualLayer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
layer
.
addAnimation
(
animation
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
=
animation
as?
CAAnimationGroup
{
a
.
delegate
=
self
layer
.
addAnimation
(
a
,
forKey
:
nil
)
visualLayer
.
addAnimation
(
a
,
forKey
:
nil
)
}
}
}
}
/**
/**
:name: animationDidStart
:name: animationDidStart
*/
*/
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{}
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{
print
(
"STARTED"
)
}
/**
/**
:name: animationDidStop
:name: animationDidStop
*/
*/
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
=
anim
as?
CABasicAnimation
{
if
let
a
=
anim
as?
CABasicAnimation
{
layer
.
setValue
(
nil
==
a
.
toValue
?
a
.
byValue
:
a
.
toValue
,
forKey
:
a
.
keyPath
!
)
visualLayer
.
removeAnimationForKey
(
a
.
keyPath
!
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
}
else
if
let
a
=
anim
as?
CAKeyframeAnimation
{
}
else
if
let
a
=
anim
as?
CAKeyframeAnimation
{
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
visualLayer
.
removeAnimationForKey
(
a
.
keyPath
!
)
}
else
if
let
a
=
anim
as?
CAAnimationGroup
{
for
x
in
a
.
animations
!
{
animationDidStop
(
x
,
finished
:
true
)
}
}
}
}
}
...
...
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