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
c81f4dfb
Commit
c81f4dfb
authored
Sep 28, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
experimental: updated animation and layering
parent
174bfbcd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
49 deletions
+80
-49
Source/MaterialButton.swift
+28
-21
Source/MaterialPulseView.swift
+45
-22
Source/MaterialTheme.swift
+1
-1
Source/MaterialView.swift
+6
-5
No files found.
Source/MaterialButton.swift
View file @
c81f4dfb
...
@@ -273,24 +273,23 @@ public class MaterialButton : UIButton {
...
@@ -273,24 +273,23 @@ public class MaterialButton : UIButton {
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
)
if
nil
!=
visualLayer
.
presentationLayer
()?
.
hitTest
(
point
)
{
// set start position
// set start position
CATransaction
.
begin
()
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0
)
CATransaction
.
setAnimationDuration
(
0
)
let
w
:
CGFloat
=
width
/
2
let
w
:
CGFloat
=
width
/
2
pulseLayer
.
hidden
=
false
pulseLayer
.
hidden
=
false
pulseLayer
.
position
=
point
pulseLayer
.
position
=
point
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
w
,
w
)
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
w
,
w
)
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
CATransaction
.
commit
()
CATransaction
.
commit
()
// expand
// expand
CATransaction
.
begin
()
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0.3
)
CATransaction
.
setAnimationDuration
(
0.3
)
pulseLayer
.
transform
=
CATransform3DMakeScale
(
2.5
,
2.5
,
2.5
)
pulseLayer
.
transform
=
CATransform3DMakeScale
(
2.5
,
2.5
,
2.5
)
visualLayer
.
transform
=
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
)
layer
.
transform
=
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
)
CATransaction
.
commit
()
CATransaction
.
commit
()
}
}
}
/**
/**
...
@@ -309,18 +308,25 @@ public class MaterialButton : UIButton {
...
@@ -309,18 +308,25 @@ public class MaterialButton : UIButton {
shrink
()
shrink
()
}
}
/**
:name: actionForLayer
*/
public
override
func
actionForLayer
(
layer
:
CALayer
,
forKey
event
:
String
)
->
CAAction
?
{
return
nil
// returning nil enables the animations for the layer property that are normally disabled.
}
//
//
// :name: prepareView
// :name: prepareView
//
//
internal
func
prepareView
()
{
internal
func
prepareView
()
{
// visualLayer
// visualLayer
layer
.
addSublayer
(
visualLayer
)
visualLayer
.
zPosition
=
-
1
visualLayer
.
zPosition
=
-
1
layer
.
addSublayer
(
visualLayer
)
// pulseLayer
// pulseLayer
pulseLayer
.
hidden
=
true
pulseLayer
.
hidden
=
true
visualLayer
.
addSublayer
(
pulseLayer
)
pulseLayer
.
zPosition
=
1000
pulseLayer
.
zPosition
=
1000
visualLayer
.
addSublayer
(
pulseLayer
)
}
}
//
//
...
@@ -338,7 +344,7 @@ public class MaterialButton : UIButton {
...
@@ -338,7 +344,7 @@ public class MaterialButton : UIButton {
CATransaction
.
setAnimationDuration
(
0.3
)
CATransaction
.
setAnimationDuration
(
0.3
)
pulseLayer
.
hidden
=
true
pulseLayer
.
hidden
=
true
pulseLayer
.
transform
=
CATransform3DIdentity
pulseLayer
.
transform
=
CATransform3DIdentity
visualL
ayer
.
transform
=
CATransform3DIdentity
l
ayer
.
transform
=
CATransform3DIdentity
CATransaction
.
commit
()
CATransaction
.
commit
()
}
}
}
}
\ No newline at end of file
Source/MaterialPulseView.swift
View file @
c81f4dfb
...
@@ -20,6 +20,11 @@ import UIKit
...
@@ -20,6 +20,11 @@ import UIKit
public
class
MaterialPulseView
:
MaterialView
{
public
class
MaterialPulseView
:
MaterialView
{
//
//
// :name: touchesLayer
//
internal
lazy
var
touchesLayer
:
CAShapeLayer
=
CAShapeLayer
()
//
// :name: pulseLayer
// :name: pulseLayer
//
//
internal
lazy
var
pulseLayer
:
CAShapeLayer
=
CAShapeLayer
()
internal
lazy
var
pulseLayer
:
CAShapeLayer
=
CAShapeLayer
()
...
@@ -41,29 +46,37 @@ public class MaterialPulseView: MaterialView {
...
@@ -41,29 +46,37 @@ public class MaterialPulseView: MaterialView {
}
}
/**
/**
:name: layoutSubviews
*/
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
touchesLayer
.
frame
=
bounds
touchesLayer
.
cornerRadius
=
layer
.
cornerRadius
}
/**
:name: touchesBegan
:name: touchesBegan
*/
*/
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
)
if
nil
!=
visualLayer
.
presentationLayer
()?
.
hitTest
(
point
)
{
// set start position
// set start position
CATransaction
.
begin
()
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0
)
CATransaction
.
setAnimationDuration
(
0
)
let
w
:
CGFloat
=
width
/
2
let
w
:
CGFloat
=
width
/
2
pulseLayer
.
hidden
=
false
pulseLayer
.
hidden
=
false
pulseLayer
.
position
=
point
pulseLayer
.
position
=
point
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
w
,
w
)
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
w
,
w
)
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
CATransaction
.
commit
()
CATransaction
.
commit
()
// expand
// expand
CATransaction
.
begin
()
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0.3
)
CATransaction
.
setAnimationDuration
(
0.3
)
pulseLayer
.
transform
=
CATransform3DMakeScale
(
2.5
,
2.5
,
2.5
)
pulseLayer
.
transform
=
CATransform3DMakeScale
(
2.5
,
2.5
,
2.5
)
visualLayer
.
transform
=
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
)
layer
.
transform
=
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
)
CATransaction
.
commit
()
CATransaction
.
commit
()
}
}
}
/**
/**
...
@@ -82,6 +95,13 @@ public class MaterialPulseView: MaterialView {
...
@@ -82,6 +95,13 @@ public class MaterialPulseView: MaterialView {
shrink
()
shrink
()
}
}
/**
:name: actionForLayer
*/
public
override
func
actionForLayer
(
layer
:
CALayer
,
forKey
event
:
String
)
->
CAAction
?
{
return
nil
// returning nil enables the animations for the layer property that are normally disabled.
}
//
//
// :name: prepareView
// :name: prepareView
//
//
...
@@ -103,10 +123,13 @@ public class MaterialPulseView: MaterialView {
...
@@ -103,10 +123,13 @@ public class MaterialPulseView: MaterialView {
borderWidth
=
MaterialTheme
.
pulseView
.
borderWidth
borderWidth
=
MaterialTheme
.
pulseView
.
borderWidth
borderColor
=
MaterialTheme
.
pulseView
.
bordercolor
borderColor
=
MaterialTheme
.
pulseView
.
bordercolor
// pulseLayer
// touchesLayer
touchesLayer
.
zPosition
=
1000
touchesLayer
.
masksToBounds
=
true
layer
.
addSublayer
(
touchesLayer
)
pulseLayer
.
hidden
=
true
pulseLayer
.
hidden
=
true
visualLayer
.
addSublayer
(
pulseLayer
)
touchesLayer
.
addSublayer
(
pulseLayer
)
pulseLayer
.
zPosition
=
1000
}
}
//
//
...
@@ -117,7 +140,7 @@ public class MaterialPulseView: MaterialView {
...
@@ -117,7 +140,7 @@ public class MaterialPulseView: MaterialView {
CATransaction
.
setAnimationDuration
(
0.3
)
CATransaction
.
setAnimationDuration
(
0.3
)
pulseLayer
.
hidden
=
true
pulseLayer
.
hidden
=
true
pulseLayer
.
transform
=
CATransform3DIdentity
pulseLayer
.
transform
=
CATransform3DIdentity
visualL
ayer
.
transform
=
CATransform3DIdentity
l
ayer
.
transform
=
CATransform3DIdentity
CATransaction
.
commit
()
CATransaction
.
commit
()
}
}
}
}
Source/MaterialTheme.swift
View file @
c81f4dfb
...
@@ -128,7 +128,7 @@ public extension MaterialTheme.navigation {
...
@@ -128,7 +128,7 @@ public extension MaterialTheme.navigation {
public
static
let
lightContentStatusBar
:
Bool
=
true
public
static
let
lightContentStatusBar
:
Bool
=
true
// interaction
// interaction
public
static
let
userInteractionEnabled
:
Bool
=
fals
e
public
static
let
userInteractionEnabled
:
Bool
=
tru
e
// image
// image
public
static
let
contentsRect
:
CGRect
=
MaterialTheme
.
view
.
contentsRect
public
static
let
contentsRect
:
CGRect
=
MaterialTheme
.
view
.
contentsRect
...
...
Source/MaterialView.swift
View file @
c81f4dfb
...
@@ -187,7 +187,7 @@ public class MaterialView: UIView {
...
@@ -187,7 +187,7 @@ public class MaterialView: UIView {
*/
*/
public
var
cornerRadius
:
MaterialRadius
!
{
public
var
cornerRadius
:
MaterialRadius
!
{
didSet
{
didSet
{
visualL
ayer
.
cornerRadius
=
MaterialRadiusToValue
(
nil
==
cornerRadius
?
.
Radius0
:
cornerRadius
!
)
l
ayer
.
cornerRadius
=
MaterialRadiusToValue
(
nil
==
cornerRadius
?
.
Radius0
:
cornerRadius
!
)
shape
=
nil
shape
=
nil
}
}
}
}
...
@@ -213,7 +213,7 @@ public class MaterialView: UIView {
...
@@ -213,7 +213,7 @@ public class MaterialView: UIView {
*/
*/
public
var
borderWidth
:
MaterialBorder
!
{
public
var
borderWidth
:
MaterialBorder
!
{
didSet
{
didSet
{
visualL
ayer
.
borderWidth
=
MaterialBorderToValue
(
nil
==
borderWidth
?
.
Border0
:
borderWidth
!
)
l
ayer
.
borderWidth
=
MaterialBorderToValue
(
nil
==
borderWidth
?
.
Border0
:
borderWidth
!
)
}
}
}
}
...
@@ -222,7 +222,7 @@ public class MaterialView: UIView {
...
@@ -222,7 +222,7 @@ public class MaterialView: UIView {
*/
*/
public
var
borderColor
:
UIColor
!
{
public
var
borderColor
:
UIColor
!
{
didSet
{
didSet
{
visualL
ayer
.
borderColor
=
nil
==
borderColor
?
MaterialColor
.
clear
.
CGColor
:
borderColor
!.
CGColor
l
ayer
.
borderColor
=
nil
==
borderColor
?
MaterialColor
.
clear
.
CGColor
:
borderColor
!.
CGColor
}
}
}
}
...
@@ -282,6 +282,7 @@ public class MaterialView: UIView {
...
@@ -282,6 +282,7 @@ public class MaterialView: UIView {
public
override
func
layoutSubviews
()
{
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
super
.
layoutSubviews
()
visualLayer
.
frame
=
bounds
visualLayer
.
frame
=
bounds
visualLayer
.
cornerRadius
=
layer
.
cornerRadius
}
}
//
//
...
@@ -304,15 +305,15 @@ public class MaterialView: UIView {
...
@@ -304,15 +305,15 @@ public class MaterialView: UIView {
borderColor
=
MaterialTheme
.
view
.
bordercolor
borderColor
=
MaterialTheme
.
view
.
bordercolor
// visualLayer
// visualLayer
layer
.
addSublayer
(
visualLayer
)
visualLayer
.
zPosition
=
-
1
visualLayer
.
zPosition
=
-
1
layer
.
addSublayer
(
visualLayer
)
}
}
//
//
// :name: prepareShape
// :name: prepareShape
//
//
internal
func
prepareShape
()
{
internal
func
prepareShape
()
{
visualL
ayer
.
cornerRadius
=
.
Square
==
shape
?
0
:
width
/
2
l
ayer
.
cornerRadius
=
.
Square
==
shape
?
0
:
width
/
2
}
}
}
}
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