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
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
111 deletions
+99
-111
Source/MaterialAnimation.swift
+29
-28
Source/MaterialBasicAnimation.swift
+27
-56
Source/MaterialKeyframeAnimation.swift
+6
-11
Source/MaterialPulseView.swift
+19
-5
Source/MaterialView.swift
+18
-11
No files found.
Source/MaterialAnimation.swift
View file @
55f9e5a3
...
...
@@ -18,6 +18,31 @@
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
{
/**
:name: disableAnimation
...
...
@@ -32,36 +57,12 @@ public struct MaterialAnimation {
/**
:name: groupAnimation
*/
public
static
func
groupAnimation
(
view
:
UIView
,
animations
:
Array
<
CAAnimation
>
,
duration
:
NSTimeInterval
=
0.5
)
{
groupAnimation
(
view
.
layer
,
animations
:
animations
,
duration
:
duration
)
}
/**
:name: groupAnimation
*/
public
static
func
groupAnimation
(
layer
:
CALayer
,
animations
:
Array
<
CAAnimation
>
,
duration
:
NSTimeInterval
=
0.5
)
{
public
static
func
groupAnimation
(
animations
:
Array
<
CAAnimation
>
,
duration
:
NSTimeInterval
=
0.5
)
->
CAAnimationGroup
{
let
group
:
CAAnimationGroup
=
CAAnimationGroup
()
group
.
fillMode
=
MaterialAnimationFillModeToValue
(
.
Forwards
)
group
.
removedOnCompletion
=
false
group
.
animations
=
animations
group
.
duration
=
duration
layer
.
addAnimation
(
group
,
forKey
:
nil
)
}
/**
: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
!
)
return
group
}
}
Source/MaterialBasicAnimation.swift
View file @
55f9e5a3
...
...
@@ -20,97 +20,67 @@ import UIKit
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
()
animation
.
keyPath
=
"backgroundColor"
animation
.
toValue
=
color
.
CGColor
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: backgroundColor
*/
public
static
func
backgroundColor
(
color
:
UIColor
,
duration
:
CFTimeInterval
=
0.25
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
backgroundColorAnimation
(
color
)
animation
.
duration
=
duration
return
animation
}
/**
:name: cornerRadiusAnimation
:name: cornerRadius
*/
public
static
func
cornerRadius
Animation
(
radius
:
CGFloat
)
->
CABasicAnimation
{
public
static
func
cornerRadius
(
radius
:
CGFloat
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"cornerRadius"
animation
.
toValue
=
radius
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: cornerRadius
*/
public
static
func
cornerRadius
(
radius
:
CGFloat
,
duration
:
CFTimeInterval
=
0.25
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
cornerRadiusAnimation
(
radius
)
animation
.
duration
=
duration
return
animation
}
/**
:name: rotationAnimation
: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
()
animation
.
keyPath
=
"transform.rotation"
animation
.
byValue
=
M_PI
*
2
*
Double
(
rotations
)
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: rotation
*/
public
static
func
rotation
(
rotations
:
Int
=
1
,
duration
:
CFTimeInterval
=
0.5
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
rotationAnimation
(
rotations
)
animation
.
duration
=
duration
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
()
animation
.
keyPath
=
"transform"
animation
.
toValue
=
NSValue
(
CATransform3D
:
transform
)
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
/**
:name: scale
*/
public
static
func
scale
(
transform
:
CATransform3D
,
duration
:
CFTimeInterval
=
0.25
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
scaleAnimation
(
transform
)
animation
.
duration
=
duration
return
animation
}
/**
:name: positionAnimation
:name: position
*/
public
static
func
position
Animation
(
point
:
CGPoint
)
->
CABasicAnimation
{
public
static
func
position
(
point
:
CGPoint
,
duration
:
CFTimeInterval
?
=
nil
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"position"
animation
.
toValue
=
NSValue
(
CGPoint
:
point
)
return
animation
}
/**
:name: position
*/
public
static
func
position
(
point
:
CGPoint
,
duration
:
CFTimeInterval
=
0.5
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
positionAnimation
(
point
)
animation
.
duration
=
duration
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
}
\ No newline at end of file
Source/MaterialKeyframeAnimation.swift
View file @
55f9e5a3
...
...
@@ -42,22 +42,16 @@ public func MaterialAnimationRotationModeToValue(mode: MaterialAnimationRotation
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
()
animation
.
keyPath
=
"position"
animation
.
path
=
bezierPath
.
CGPath
animation
.
rotationMode
=
MaterialAnimationRotationModeToValue
(
mode
)
return
animation
}
/**
: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
if
let
d
=
duration
{
animation
.
duration
=
d
}
return
animation
}
}
\ No newline at end of file
Source/MaterialPulseView.swift
View file @
55f9e5a3
...
...
@@ -64,12 +64,12 @@ public class MaterialPulseView : MaterialView {
public
override
func
touchesBegan
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
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
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
w
,
w
)
MaterialAnimation
.
disableAnimation
({
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
s
,
s
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
self
.
pulseLayer
.
cornerRadius
=
s
/
2
})
pulseLayer
.
hidden
=
false
...
...
@@ -100,6 +100,20 @@ public class MaterialPulseView : MaterialView {
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
//
...
...
@@ -109,7 +123,7 @@ public class MaterialPulseView : MaterialView {
backgroundColor
=
MaterialTheme
.
pulseView
.
backgroundColor
pulseColorOpacity
=
MaterialTheme
.
pulseView
.
pulseColorOpacity
pulseColor
=
MaterialTheme
.
pulseView
.
pulseColor
contentsRect
=
MaterialTheme
.
pulseView
.
contentsRect
contentsCenter
=
MaterialTheme
.
pulseView
.
contentsCenter
contentsScale
=
MaterialTheme
.
pulseView
.
contentsScale
...
...
Source/MaterialView.swift
View file @
55f9e5a3
...
...
@@ -305,31 +305,38 @@ public class MaterialView : UIView {
if
let
a
=
animation
as?
CABasicAnimation
{
a
.
fromValue
=
(
nil
==
layer
.
presentationLayer
()
?
layer
:
layer
.
presentationLayer
()
as!
CALayer
)
.
valueForKeyPath
(
a
.
keyPath
!
)
a
.
delegate
=
self
a
.
fillMode
=
kCAFillModeForwards
a
.
removedOnCompletion
=
false
layer
.
addAnimation
(
animation
,
forKey
:
a
.
keyPath
!
)
layer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
visualLayer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
=
animation
as?
CAKeyframeAnimation
{
a
.
delegate
=
self
a
.
fillMode
=
kCAFillModeForwards
a
.
removedOnCompletion
=
false
layer
.
addAnimation
(
animation
,
forKey
:
a
.
keyPath
!
)
layer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
visualLayer
.
addAnimation
(
a
,
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
*/
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{}
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{
print
(
"STARTED"
)
}
/**
:name: animationDidStop
*/
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
=
anim
as?
CABasicAnimation
{
layer
.
setValue
(
nil
==
a
.
toValue
?
a
.
byValue
:
a
.
toValue
,
forKey
:
a
.
keyPath
!
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
visualLayer
.
removeAnimationForKey
(
a
.
keyPath
!
)
}
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
)
}
}
}
...
...
@@ -339,7 +346,7 @@ public class MaterialView : UIView {
internal
func
prepareView
()
{
userInteractionEnabled
=
MaterialTheme
.
view
.
userInteractionEnabled
backgroundColor
=
MaterialTheme
.
view
.
backgroundColor
contentsRect
=
MaterialTheme
.
view
.
contentsRect
contentsCenter
=
MaterialTheme
.
view
.
contentsCenter
contentsScale
=
MaterialTheme
.
view
.
contentsScale
...
...
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