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
f98360e5
Commit
f98360e5
authored
Oct 09, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding MaterialLayer basics
parent
e59a6f3e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
80 deletions
+99
-80
Source/MaterialButton.swift
+23
-38
Source/MaterialLayer.swift
+49
-0
Source/MaterialView.swift
+27
-42
No files found.
Source/MaterialButton.swift
View file @
f98360e5
...
@@ -21,6 +21,20 @@ import UIKit
...
@@ -21,6 +21,20 @@ import UIKit
@objc(MaterialButton)
@objc(MaterialButton)
public
class
MaterialButton
:
UIButton
{
public
class
MaterialButton
:
UIButton
{
/**
/**
:name: layerClass
*/
public
override
class
func
layerClass
()
->
AnyClass
{
return
MaterialLayer
.
self
}
/**
:name: materialLayer
*/
public
var
materialLayer
:
MaterialLayer
{
return
layer
as!
MaterialLayer
}
/**
:name: visualLayer
:name: visualLayer
*/
*/
public
private(set)
lazy
var
visualLayer
:
CAShapeLayer
=
CAShapeLayer
()
public
private(set)
lazy
var
visualLayer
:
CAShapeLayer
=
CAShapeLayer
()
...
@@ -33,7 +47,14 @@ public class MaterialButton : UIButton {
...
@@ -33,7 +47,14 @@ public class MaterialButton : UIButton {
/**
/**
:name: delegate
:name: delegate
*/
*/
public
weak
var
delegate
:
MaterialAnimationDelegate
?
public
weak
var
delegate
:
MaterialAnimationDelegate
?
{
get
{
return
materialLayer
.
animationDelegate
}
set
(
value
)
{
materialLayer
.
animationDelegate
=
delegate
}
}
/**
/**
:name: pulseScale
:name: pulseScale
...
@@ -338,43 +359,7 @@ public class MaterialButton : UIButton {
...
@@ -338,43 +359,7 @@ public class MaterialButton : UIButton {
:name: animation
:name: animation
*/
*/
public
func
animation
(
animation
:
CAAnimation
)
{
public
func
animation
(
animation
:
CAAnimation
)
{
animation
.
delegate
=
self
materialLayer
.
animation
(
animation
)
if
let
a
:
CABasicAnimation
=
animation
as?
CABasicAnimation
{
a
.
fromValue
=
(
nil
==
layer
.
presentationLayer
()
?
layer
:
layer
.
presentationLayer
()
as!
CALayer
)
.
valueForKeyPath
(
a
.
keyPath
!
)
}
if
let
a
:
CAPropertyAnimation
=
animation
as?
CAPropertyAnimation
{
layer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
animation
as?
CAAnimationGroup
{
layer
.
addAnimation
(
a
,
forKey
:
nil
)
}
else
if
let
a
:
CATransition
=
animation
as?
CATransition
{
layer
.
addAnimation
(
a
,
forKey
:
kCATransition
)
}
}
/**
:name: animationDidStart
*/
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{
delegate
?
.
materialAnimationDidStart
?(
anim
)
}
/**
:name: animationDidStop
*/
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
({
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
})
}
delegate
?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
anim
as?
CAAnimationGroup
{
for
x
in
a
.
animations
!
{
animationDidStop
(
x
,
finished
:
true
)
}
}
}
}
/**
/**
...
...
Source/MaterialLayer.swift
View file @
f98360e5
...
@@ -18,8 +18,14 @@
...
@@ -18,8 +18,14 @@
import
UIKit
import
UIKit
@objc(MaterialLayer)
public
class
MaterialLayer
:
CAShapeLayer
{
public
class
MaterialLayer
:
CAShapeLayer
{
/**
/**
:name: animationDelegate
*/
public
var
animationDelegate
:
MaterialAnimationDelegate
?
/**
:name: init
:name: init
*/
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
...
@@ -39,5 +45,48 @@ public class MaterialLayer : CAShapeLayer {
...
@@ -39,5 +45,48 @@ public class MaterialLayer : CAShapeLayer {
public
override
init
()
{
public
override
init
()
{
super
.
init
()
super
.
init
()
}
}
/**
:name: animation
*/
public
func
animation
(
animation
:
CAAnimation
)
{
animation
.
delegate
=
self
if
let
a
:
CABasicAnimation
=
animation
as?
CABasicAnimation
{
a
.
fromValue
=
(
nil
==
presentationLayer
()
?
self
:
presentationLayer
()
as!
CALayer
)
.
valueForKeyPath
(
a
.
keyPath
!
)
}
if
let
a
:
CAPropertyAnimation
=
animation
as?
CAPropertyAnimation
{
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
animation
as?
CAAnimationGroup
{
addAnimation
(
a
,
forKey
:
nil
)
}
else
if
let
a
:
CATransition
=
animation
as?
CATransition
{
addAnimation
(
a
,
forKey
:
kCATransition
)
}
}
/**
:name: animationDidStart
*/
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{
animationDelegate
?
.
materialAnimationDidStart
?(
anim
)
}
/**
:name: animationDidStop
*/
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
({
self
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
})
}
animationDelegate
?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
removeAnimationForKey
(
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
anim
as?
CAAnimationGroup
{
for
x
in
a
.
animations
!
{
animationDidStop
(
x
,
finished
:
true
)
}
}
}
}
}
Source/MaterialView.swift
View file @
f98360e5
...
@@ -20,15 +20,36 @@ import UIKit
...
@@ -20,15 +20,36 @@ import UIKit
@objc(MaterialView)
@objc(MaterialView)
public
class
MaterialView
:
UIView
{
public
class
MaterialView
:
UIView
{
//
/**
// :name: visualLayer
:name: layerClass
//
*/
public
private(set)
lazy
var
visualLayer
:
CAShapeLayer
=
CAShapeLayer
()
public
override
class
func
layerClass
()
->
AnyClass
{
return
MaterialLayer
.
self
}
/**
:name: materialLayer
*/
public
var
materialLayer
:
MaterialLayer
{
return
layer
as!
MaterialLayer
}
/**
/**
:name: visualLayer
:name: visualLayer
*/
*/
public
weak
var
delegate
:
MaterialAnimationDelegate
?
public
private(set)
lazy
var
visualLayer
:
CAShapeLayer
=
CAShapeLayer
()
/**
:name: delegate
*/
public
weak
var
delegate
:
MaterialAnimationDelegate
?
{
get
{
return
materialLayer
.
animationDelegate
}
set
(
value
)
{
materialLayer
.
animationDelegate
=
delegate
}
}
/**
/**
:name: image
:name: image
...
@@ -330,43 +351,7 @@ public class MaterialView : UIView {
...
@@ -330,43 +351,7 @@ public class MaterialView : UIView {
:name: animation
:name: animation
*/
*/
public
func
animation
(
animation
:
CAAnimation
)
{
public
func
animation
(
animation
:
CAAnimation
)
{
animation
.
delegate
=
self
materialLayer
.
animation
(
animation
)
if
let
a
:
CABasicAnimation
=
animation
as?
CABasicAnimation
{
a
.
fromValue
=
(
nil
==
layer
.
presentationLayer
()
?
layer
:
layer
.
presentationLayer
()
as!
CALayer
)
.
valueForKeyPath
(
a
.
keyPath
!
)
}
if
let
a
:
CAPropertyAnimation
=
animation
as?
CAPropertyAnimation
{
layer
.
addAnimation
(
a
,
forKey
:
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
animation
as?
CAAnimationGroup
{
layer
.
addAnimation
(
a
,
forKey
:
nil
)
}
else
if
let
a
:
CATransition
=
animation
as?
CATransition
{
layer
.
addAnimation
(
a
,
forKey
:
kCATransition
)
}
}
/**
:name: animationDidStart
*/
public
override
func
animationDidStart
(
anim
:
CAAnimation
)
{
delegate
?
.
materialAnimationDidStart
?(
anim
)
}
/**
:name: animationDidStop
*/
public
override
func
animationDidStop
(
anim
:
CAAnimation
,
finished
flag
:
Bool
)
{
if
let
a
:
CAPropertyAnimation
=
anim
as?
CAPropertyAnimation
{
if
let
b
:
CABasicAnimation
=
a
as?
CABasicAnimation
{
MaterialAnimation
.
animationDisabled
({
self
.
layer
.
setValue
(
nil
==
b
.
toValue
?
b
.
byValue
:
b
.
toValue
,
forKey
:
b
.
keyPath
!
)
})
}
delegate
?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
layer
.
removeAnimationForKey
(
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
anim
as?
CAAnimationGroup
{
for
x
in
a
.
animations
!
{
animationDidStop
(
x
,
finished
:
true
)
}
}
}
}
//
//
...
...
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