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
0b014dfd
Commit
0b014dfd
authored
Sep 28, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added spin animation and cleaned up pulseView
parent
cb4c9195
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
21 deletions
+16
-21
Source/MaterialAnimation.swift
+7
-18
Source/MaterialPulseView.swift
+9
-3
No files found.
Source/MaterialAnimation.swift
View file @
0b014dfd
...
@@ -20,24 +20,13 @@ import UIKit
...
@@ -20,24 +20,13 @@ import UIKit
public
struct
MaterialAnimation
{
public
struct
MaterialAnimation
{
/**
/**
:name:
rotate
:name:
spin
*/
*/
public
static
func
rotate
(
layer
:
CALayer
,
duration
:
CFTimeInterval
,
completion
:
(()
->
Void
)?
=
nil
)
{
public
static
func
spin
(
layer
:
CALayer
,
duration
:
CFTimeInterval
,
rotations
:
Int
=
1
,
completion
:
(()
->
Void
)?
=
nil
)
{
CATransaction
.
begin
()
let
a
:
CABasicAnimation
=
CABasicAnimation
()
CATransaction
.
setAnimationDuration
(
duration
)
a
.
keyPath
=
"transform.rotation"
let
transform
:
CGAffineTransform
=
CGAffineTransformRotate
(
layer
.
affineTransform
(),
CGFloat
(
M_PI
))
a
.
duration
=
duration
layer
.
setAffineTransform
(
transform
)
a
.
byValue
=
M_PI
*
2
*
Double
(
rotations
)
CATransaction
.
setCompletionBlock
(
completion
)
layer
.
addAnimation
(
a
,
forKey
:
nil
)
CATransaction
.
commit
()
}
/**
:name: pulse
*/
public
static
func
pulse
(
layer
:
CALayer
,
duraction
:
CFTimeInterval
,
completion
:
(()
->
Void
)?
=
nil
)
{
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
1.0
)
CATransaction
.
commit
()
}
}
}
}
Source/MaterialPulseView.swift
View file @
0b014dfd
...
@@ -27,7 +27,11 @@ public class MaterialPulseView: MaterialView {
...
@@ -27,7 +27,11 @@ public class MaterialPulseView: MaterialView {
/**
/**
:name: pulseColor
:name: pulseColor
*/
*/
public
var
pulseColor
:
UIColor
?
public
var
pulseColor
:
UIColor
?
{
didSet
{
pulseLayer
.
backgroundColor
=
pulseColor
?
.
colorWithAlphaComponent
(
0.5
)
.
CGColor
}
}
/**
/**
:name: init
:name: init
...
@@ -43,6 +47,7 @@ public class MaterialPulseView: MaterialView {
...
@@ -43,6 +47,7 @@ public class MaterialPulseView: MaterialView {
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
let
point
:
CGPoint
=
touches
.
first
!.
locationInView
(
self
)
let
point
:
CGPoint
=
touches
.
first
!.
locationInView
(
self
)
if
nil
!=
visualLayer
.
presentationLayer
()?
.
hitTest
(
point
)
{
if
nil
!=
visualLayer
.
presentationLayer
()?
.
hitTest
(
point
)
{
// set start position
CATransaction
.
begin
()
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0
)
CATransaction
.
setAnimationDuration
(
0
)
let
w
:
CGFloat
=
width
/
2
let
w
:
CGFloat
=
width
/
2
...
@@ -52,6 +57,7 @@ public class MaterialPulseView: MaterialView {
...
@@ -52,6 +57,7 @@ public class MaterialPulseView: MaterialView {
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
CATransaction
.
commit
()
CATransaction
.
commit
()
// expand
CATransaction
.
begin
()
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0.3
)
CATransaction
.
setAnimationDuration
(
0.3
)
pulseLayer
.
transform
=
CATransform3DMakeScale
(
2
,
2
,
2
)
pulseLayer
.
transform
=
CATransform3DMakeScale
(
2
,
2
,
2
)
...
@@ -65,6 +71,7 @@ public class MaterialPulseView: MaterialView {
...
@@ -65,6 +71,7 @@ public class MaterialPulseView: MaterialView {
*/
*/
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
// contract
CATransaction
.
begin
()
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0.3
)
CATransaction
.
setAnimationDuration
(
0.3
)
pulseLayer
.
hidden
=
true
pulseLayer
.
hidden
=
true
...
@@ -109,7 +116,6 @@ public class MaterialPulseView: MaterialView {
...
@@ -109,7 +116,6 @@ public class MaterialPulseView: MaterialView {
// pulseLayer
// pulseLayer
pulseLayer
.
hidden
=
true
pulseLayer
.
hidden
=
true
pulseLayer
.
backgroundColor
=
pulseColor
?
.
colorWithAlphaComponent
(
0.5
)
.
CGColor
visualLayer
.
insertSublayer
(
pulseLayer
,
atIndex
:
1000
)
visualLayer
.
addSublayer
(
pulseLayer
)
}
}
}
}
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