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
a202a838
Commit
a202a838
authored
Oct 02, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Animation Group added
parent
b5cecbfc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
42 deletions
+108
-42
Source/MaterialAnimation.swift
+20
-2
Source/MaterialBasicAnimation.swift
+69
-17
Source/MaterialKeyframeAnimation.swift
+15
-19
Source/MaterialPulseView.swift
+4
-4
No files found.
Source/MaterialAnimation.swift
View file @
a202a838
...
...
@@ -30,9 +30,26 @@ public struct MaterialAnimation {
}
/**
:name: groupAnimation
*/
public
static
func
groupAnimation
(
view
:
UIView
,
animations
:
Array
<
CAAnimation
>
,
duration
:
NSTimeInterval
=
0.5
)
{
return
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
()
group
.
animations
=
animations
group
.
duration
=
duration
layer
.
addAnimation
(
group
,
forKey
:
nil
)
}
/**
:name: applyBasicAnimation
*/
public
static
func
applyBasicAnimation
(
animation
:
CABasicAnimation
,
toLayer
layer
:
CALayer
,
completion
:
(()
->
Void
)?
=
nil
)
{
internal
static
func
applyBasicAnimation
(
animation
:
CABasicAnimation
,
toLayer
layer
:
CALayer
,
completion
:
(()
->
Void
)?
=
nil
)
{
// use presentation layer if available
animation
.
fromValue
=
(
nil
==
layer
.
presentationLayer
()
?
layer
:
layer
.
presentationLayer
()
as!
CALayer
)
.
valueForKeyPath
(
animation
.
keyPath
!
)
CATransaction
.
begin
()
...
...
@@ -50,8 +67,9 @@ public struct MaterialAnimation {
/**
:name: applyKeyframeAnimation
*/
public
static
func
applyKeyframeAnimation
(
animation
:
CAKeyframeAnimation
,
toLayer
layer
:
CALayer
,
completion
:
(()
->
Void
)?
=
nil
)
{
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
:
nil
)
}
}
Source/MaterialBasicAnimation.swift
View file @
a202a838
...
...
@@ -20,53 +20,106 @@ import UIKit
public
extension
MaterialAnimation
{
/**
:name: backgroundColor
:name: backgroundColor
Animation
*/
public
static
func
backgroundColor
(
layer
:
CALayer
,
color
:
UIColor
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
public
static
func
backgroundColor
Animation
(
color
:
UIColor
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"backgroundColor"
animation
.
duration
=
duration
animation
.
toValue
=
color
.
CGColor
applyBasicAnimation
(
animation
,
toLayer
:
layer
,
completion
:
completion
)
return
animation
}
/**
:name:
rotate
:name:
backgroundColor
*/
public
static
func
rotate
(
view
:
UIView
,
rotations
:
Int
=
1
,
duration
:
CFTimeInterval
=
0.5
,
completion
:
(()
->
Void
)?
=
nil
)
{
rotate
(
view
.
layer
,
rotations
:
rotations
,
duration
:
duration
,
completion
:
completion
)
public
static
func
backgroundColor
(
view
:
UIView
,
color
:
UIColor
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
backgroundColor
(
view
.
layer
,
color
:
color
,
duration
:
duration
,
completion
:
completion
)
}
/**
:name: backgroundColor
*/
public
static
func
backgroundColor
(
layer
:
CALayer
,
color
:
UIColor
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
animation
:
CABasicAnimation
=
backgroundColorAnimation
(
color
)
animation
.
duration
=
duration
applyBasicAnimation
(
animation
,
toLayer
:
layer
,
completion
:
completion
)
}
/**
:name: rotat
e
:name: rotat
ionAnimation
*/
public
static
func
rotat
e
(
layer
:
CALayer
,
rotations
:
Int
=
1
,
duration
:
CFTimeInterval
=
0.5
,
completion
:
(()
->
Void
)?
=
nil
)
{
public
static
func
rotat
ionAnimation
(
rotations
:
Int
=
1
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform.rotation"
animation
.
duration
=
duration
animation
.
byValue
=
M_PI
*
2
*
Double
(
rotations
)
return
animation
}
/**
:name: rotation
*/
public
static
func
rotation
(
view
:
UIView
,
rotations
:
Int
=
1
,
duration
:
CFTimeInterval
=
0.5
,
completion
:
(()
->
Void
)?
=
nil
)
{
rotation
(
view
.
layer
,
rotations
:
rotations
,
duration
:
duration
,
completion
:
completion
)
}
/**
:name: rotation
*/
public
static
func
rotation
(
layer
:
CALayer
,
rotations
:
Int
=
1
,
duration
:
CFTimeInterval
=
0.5
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
animation
:
CABasicAnimation
=
rotationAnimation
(
rotations
)
animation
.
duration
=
duration
applyBasicAnimation
(
animation
,
toLayer
:
layer
,
completion
:
completion
)
}
/**
:name: transform
:name: transform
Animation
*/
public
static
func
transform
(
layer
:
CALayer
,
scale
:
CATransform3D
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
public
static
func
transform
Animation
(
scale
:
CATransform3D
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform"
animation
.
duration
=
duration
animation
.
toValue
=
NSValue
(
CATransform3D
:
scale
)
return
animation
}
/**
:name: transform
*/
public
static
func
transform
(
view
:
UIView
,
rotations
:
Int
=
1
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
rotation
(
view
.
layer
,
rotations
:
rotations
,
duration
:
duration
,
completion
:
completion
)
}
/**
:name: transform
*/
public
static
func
transform
(
layer
:
CALayer
,
scale
:
CATransform3D
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
animation
:
CABasicAnimation
=
transformAnimation
(
scale
)
animation
.
duration
=
duration
applyBasicAnimation
(
animation
,
toLayer
:
layer
,
completion
:
completion
)
}
/**
:name: cornerRadius
:name: cornerRadius
Animation
*/
public
static
func
cornerRadius
(
layer
:
CALayer
,
radius
:
CGFloat
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
public
static
func
cornerRadius
Animation
(
radius
:
CGFloat
)
->
CABasicAnimation
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"cornerRadius"
animation
.
toValue
=
radius
return
animation
}
/**
:name: cornerRadius
*/
public
static
func
cornerRadius
(
view
:
UIView
,
radius
:
CGFloat
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
cornerRadius
(
view
.
layer
,
radius
:
radius
,
duration
:
duration
,
completion
:
completion
)
}
/**
:name: cornerRadius
*/
public
static
func
cornerRadius
(
layer
:
CALayer
,
radius
:
CGFloat
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
animation
:
CABasicAnimation
=
cornerRadiusAnimation
(
radius
)
animation
.
duration
=
duration
animation
.
byValue
=
radius
applyBasicAnimation
(
animation
,
toLayer
:
layer
,
completion
:
completion
)
}
}
\ No newline at end of file
Source/MaterialKeyframeAnimation.swift
View file @
a202a838
...
...
@@ -42,32 +42,29 @@ public func MaterialAnimationRotationModeToValue(mode: MaterialAnimationRotation
public
extension
MaterialAnimation
{
/**
:name: positionAnimation
*/
public
static
func
positionAnimation
(
path
:
UIBezierPath
,
mode
:
MaterialAnimationRotationMode
=
.
Auto
)
->
CAKeyframeAnimation
{
let
animation
:
CAKeyframeAnimation
=
CAKeyframeAnimation
()
animation
.
keyPath
=
"position"
animation
.
path
=
path
.
CGPath
animation
.
rotationMode
=
MaterialAnimationRotationModeToValue
(
mode
)
return
animation
}
/**
:name: position
*/
public
static
func
position
(
view
:
UIView
,
path
:
UIBezierPath
,
mode
:
MaterialAnimationRotationMode
=
.
Auto
,
duration
:
CFTimeInterval
=
1
,
completion
:
(()
->
Void
)?
=
nil
)
{
position
(
view
.
layer
,
path
:
path
,
mode
:
mode
,
duration
:
duration
,
completion
:
completion
)
public
static
func
position
(
view
:
UIView
,
path
:
UIBezierPath
,
mode
:
MaterialAnimationRotationMode
=
.
Auto
,
duration
:
CFTimeInterval
=
1
)
{
position
(
view
.
layer
,
path
:
path
,
mode
:
mode
,
duration
:
duration
)
}
/**
:name: position
*/
public
static
func
position
(
layer
:
CALayer
,
path
:
UIBezierPath
,
mode
:
MaterialAnimationRotationMode
=
.
Auto
,
duration
:
CFTimeInterval
=
1
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
animation
:
CAKeyframeAnimation
=
CAKeyframeAnimation
()
animation
.
keyPath
=
"position"
public
static
func
position
(
layer
:
CALayer
,
path
:
UIBezierPath
,
mode
:
MaterialAnimationRotationMode
=
.
Auto
,
duration
:
CFTimeInterval
=
1
)
{
let
animation
:
CAKeyframeAnimation
=
positionAnimation
(
path
,
mode
:
mode
)
animation
.
duration
=
duration
animation
.
path
=
path
.
CGPath
animation
.
rotationMode
=
MaterialAnimationRotationModeToValue
(
mode
)
applyKeyframeAnimation
(
animation
,
toLayer
:
layer
)
}
}
\ No newline at end of file
Source/MaterialPulseView.swift
View file @
a202a838
...
...
@@ -80,8 +80,8 @@ public class MaterialPulseView : MaterialView {
})
pulseLayer
.
hidden
=
false
pulseLayer
.
transform
=
CATransform3DMakeScale
(
3
,
3
,
3
)
layer
.
transform
=
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
)
MaterialAnimation
.
transform
(
pulseLayer
,
scale
:
CATransform3DMakeScale
(
3
,
3
,
3
)
)
MaterialAnimation
.
transform
(
layer
,
scale
:
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
)
)
}
/**
...
...
@@ -151,7 +151,7 @@ public class MaterialPulseView : MaterialView {
//
internal
func
shrink
()
{
pulseLayer
.
hidden
=
true
pulseLayer
.
transform
=
CATransform3DIdentity
layer
.
transform
=
CATransform3DIdentity
MaterialAnimation
.
transform
(
pulseLayer
,
scale
:
CATransform3DIdentity
)
MaterialAnimation
.
transform
(
layer
,
scale
:
CATransform3DIdentity
)
}
}
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