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
785bd813
Commit
785bd813
authored
Oct 03, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated hitTest with containsPoint for animation accuracy
parent
55f9e5a3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
65 deletions
+55
-65
Source/MaterialKeyframeAnimation.swift
+1
-1
Source/MaterialPulseView.swift
+17
-46
Source/MaterialView.swift
+37
-18
No files found.
Source/MaterialKeyframeAnimation.swift
View file @
785bd813
...
...
@@ -44,7 +44,7 @@ public extension MaterialAnimation {
/**
:name: path
*/
public
static
func
path
(
bezierPath
:
UIBezierPath
,
duration
:
CFTimeInterval
?,
mode
:
MaterialAnimationRotationMode
=
.
Auto
)
->
CAKeyframeAnimation
{
public
static
func
path
(
bezierPath
:
UIBezierPath
,
mode
:
MaterialAnimationRotationMode
=
.
Auto
,
duration
:
CFTimeInterval
?
=
nil
)
->
CAKeyframeAnimation
{
let
animation
:
CAKeyframeAnimation
=
CAKeyframeAnimation
()
animation
.
keyPath
=
"position"
animation
.
path
=
bezierPath
.
CGPath
...
...
Source/MaterialPulseView.swift
View file @
785bd813
...
...
@@ -20,11 +20,6 @@ import UIKit
public
class
MaterialPulseView
:
MaterialView
{
//
// :name: touchesLayer
//
internal
lazy
var
touchesLayer
:
CAShapeLayer
=
CAShapeLayer
()
//
// :name: pulseLayer
//
internal
lazy
var
pulseLayer
:
CAShapeLayer
=
CAShapeLayer
()
...
...
@@ -50,31 +45,25 @@ public class MaterialPulseView : MaterialView {
}
/**
:name: layoutSubviews
*/
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
touchesLayer
.
frame
=
bounds
touchesLayer
.
cornerRadius
=
layer
.
cornerRadius
}
/**
:name: touchesBegan
*/
public
override
func
touchesBegan
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
let
point
:
CGPoint
=
touches
.
first
!.
locationInView
(
self
)
let
s
:
CGFloat
=
(
width
<
height
?
height
:
width
)
/
2
MaterialAnimation
.
disableAnimation
({
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
s
,
s
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
s
/
2
})
pulseLayer
.
hidden
=
false
pulseLayer
.
transform
=
CATransform3DMakeScale
(
3
,
3
,
3
)
layer
.
transform
=
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
)
var
point
:
CGPoint
=
touches
.
first
!.
locationInView
(
self
)
point
=
layer
.
convertPoint
(
point
,
fromLayer
:
layer
)
if
true
==
layer
.
containsPoint
(
point
)
{
let
s
:
CGFloat
=
(
width
<
height
?
height
:
width
)
/
2
MaterialAnimation
.
disableAnimation
({
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
s
,
s
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
s
/
2
})
pulseLayer
.
hidden
=
false
pulseLayer
.
transform
=
CATransform3DMakeScale
(
3
,
3
,
3
)
layer
.
transform
=
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
)
}
}
/**
...
...
@@ -100,20 +89,6 @@ 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
//
...
...
@@ -136,14 +111,10 @@ public class MaterialPulseView : MaterialView {
borderWidth
=
MaterialTheme
.
pulseView
.
borderWidth
borderColor
=
MaterialTheme
.
pulseView
.
bordercolor
// touchesLayer
touchesLayer
.
zPosition
=
1000
touchesLayer
.
masksToBounds
=
true
layer
.
addSublayer
(
touchesLayer
)
// pulseLayer
pulseLayer
.
hidden
=
true
touchesLayer
.
addSublayer
(
pulseLayer
)
pulseLayer
.
zPosition
=
1
visualLayer
.
addSublayer
(
pulseLayer
)
}
//
...
...
Source/MaterialView.swift
View file @
785bd813
...
...
@@ -299,21 +299,21 @@ public class MaterialView : UIView {
}
/**
:name: a
ddA
nimation
:name: animation
*/
public
func
addAnimation
(
animation
:
CAAnimation
)
{
if
let
a
=
animation
as?
CABasicAnimation
{
public
func
animation
(
animation
:
CAAnimation
)
{
animation
.
delegate
=
self
if
let
a
:
CABasicAnimation
=
animation
as?
CABasicAnimation
{
a
.
fromValue
=
(
nil
==
layer
.
presentationLayer
()
?
layer
:
layer
.
presentationLayer
()
as!
CALayer
)
.
valueForKeyPath
(
a
.
keyPath
!
)
a
.
delegate
=
self
layer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
visualLayer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
=
animation
as?
CAKeyframeAnimation
{
a
.
delegate
=
self
}
if
let
a
:
CAPropertyAnimation
=
animation
as?
CAPropertyAnimation
{
layer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
visualLayer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
=
animation
as?
CAAnimationGroup
{
a
.
delegate
=
self
if
true
==
filterAnimations
(
a
)
{
visualLayer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
}
else
if
let
a
:
CAAnimationGroup
=
animation
as?
CAAnimationGroup
{
layer
.
addAnimation
(
a
,
forKey
:
nil
)
filterAnimations
(
a
)
visualLayer
.
addAnimation
(
a
,
forKey
:
nil
)
}
}
...
...
@@ -321,19 +321,22 @@ public class MaterialView : UIView {
/**
:name: animationDidStart
*/
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{
print
(
"STARTED"
)
}
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{}
/**
:name: animationDidStop
*/
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
=
anim
as?
CABasicAnimation
{
visualLayer
.
removeAnimationForKey
(
a
.
keyPath
!
)
}
else
if
let
a
=
anim
as?
CAKeyframeAnimation
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
CATransaction
.
begin
()
CATransaction
.
setDisableActions
(
true
)
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
CATransaction
.
commit
()
}
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
visualLayer
.
removeAnimationForKey
(
a
.
keyPath
!
)
}
else
if
let
a
=
anim
as?
CAAnimationGroup
{
}
else
if
let
a
:
CAAnimationGroup
=
anim
as?
CAAnimationGroup
{
for
x
in
a
.
animations
!
{
animationDidStop
(
x
,
finished
:
true
)
}
...
...
@@ -341,6 +344,22 @@ public class MaterialView : UIView {
}
//
// :name: filterAnimations
//
internal
func
filterAnimations
(
animation
:
CAAnimation
)
->
Bool
?
{
if
let
a
:
CAPropertyAnimation
=
animation
as?
CAPropertyAnimation
{
return
"position"
!=
a
.
keyPath
}
else
if
let
a
:
CAAnimationGroup
=
animation
as?
CAAnimationGroup
{
for
var
i
:
Int
=
a
.
animations
!.
count
-
1
;
0
<=
i
;
--
i
{
if
false
==
filterAnimations
(
a
.
animations
!
[
i
])
{
a
.
animations
!.
removeAtIndex
(
i
)
}
}
}
return
nil
}
//
// :name: prepareView
//
internal
func
prepareView
()
{
...
...
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