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
68026aad
Commit
68026aad
authored
Oct 02, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added base animations to MaterialAnimation
parent
e73d83f3
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
132 additions
and
84 deletions
+132
-84
Source/BasicCardView.swift
+3
-3
Source/FabButton.swift
+0
-7
Source/MaterialAnimation.swift
+79
-7
Source/MaterialButton.swift
+25
-33
Source/MaterialLabel.swift
+1
-1
Source/MaterialPulseView.swift
+9
-18
Source/MaterialView.swift
+14
-14
Source/NavigationBarView.swift
+1
-1
No files found.
Source/BasicCardView.swift
View file @
68026aad
...
...
@@ -18,7 +18,7 @@
import
UIKit
public
class
BasicCardView
:
MaterialPulseView
{
public
class
BasicCardView
:
MaterialPulseView
{
//
// :name: dividerLayer
//
...
...
@@ -208,14 +208,14 @@ public class BasicCardView: MaterialPulseView {
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRect
Zero
)
self
.
init
(
frame
:
CGRect
Null
)
}
/**
:name: init
*/
public
convenience
init
?(
titleLabel
:
UILabel
?
=
nil
,
detailLabel
:
UILabel
?
=
nil
,
leftButtons
:
Array
<
MaterialButton
>
?
=
nil
,
rightButtons
:
Array
<
MaterialButton
>
?
=
nil
)
{
self
.
init
(
frame
:
CGRect
Zero
)
self
.
init
(
frame
:
CGRect
Null
)
self
.
prepareProperties
(
titleLabel
,
detailLabel
:
detailLabel
,
leftButtons
:
leftButtons
,
rightButtons
:
rightButtons
)
}
...
...
Source/FabButton.swift
View file @
68026aad
...
...
@@ -19,13 +19,6 @@
import
UIKit
public
class
FabButton
:
MaterialButton
{
/**
:name: layoutSubviews
*/
public
override
func
layoutSubviews
()
{
super
.
layoutSubviews
()
}
//
// :name: prepareView
//
...
...
Source/MaterialAnimation.swift
View file @
68026aad
...
...
@@ -20,13 +20,85 @@ import UIKit
public
struct
MaterialAnimation
{
/**
:name:
spin
:name:
backgroundColor
*/
public
static
func
spin
(
view
:
UIView
,
duration
:
CFTimeInterval
=
1
,
rotations
:
Int
=
1
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
a
:
CABasicAnimation
=
CABasicAnimation
()
a
.
keyPath
=
"transform.rotation"
a
.
duration
=
duration
a
.
byValue
=
M_PI
*
2
*
Double
(
rotations
)
view
.
layer
.
addAnimation
(
a
,
forKey
:
nil
)
public
static
func
backgroundColor
(
layer
:
CALayer
,
color
:
UIColor
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"backgroundColor"
animation
.
duration
=
duration
animation
.
toValue
=
color
.
CGColor
applyBasicAnimation
(
animation
,
layer
:
layer
,
completion
:
completion
)
}
/**
:name: rotate
*/
public
static
func
rotate
(
layer
:
CALayer
,
rotations
:
Int
=
1
,
duration
:
CFTimeInterval
=
0.5
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform.rotation"
animation
.
duration
=
duration
animation
.
byValue
=
M_PI
*
2
*
Double
(
rotations
)
applyBasicAnimation
(
animation
,
layer
:
layer
,
completion
:
completion
)
}
/**
:name: transform
*/
public
static
func
transform
(
layer
:
CALayer
,
scale
:
CATransform3D
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"transform"
animation
.
duration
=
duration
animation
.
toValue
=
NSValue
(
CATransform3D
:
scale
)
applyBasicAnimation
(
animation
,
layer
:
layer
,
completion
:
completion
)
}
/**
:name: position
*/
public
static
func
position
(
layer
:
CALayer
,
point
:
CGPoint
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"position"
animation
.
duration
=
duration
animation
.
toValue
=
NSValue
(
CGPoint
:
point
)
applyBasicAnimation
(
animation
,
layer
:
layer
,
completion
:
completion
)
}
/**
:name: cornerRadius
*/
public
static
func
cornerRadius
(
layer
:
CALayer
,
radius
:
CGFloat
,
duration
:
CFTimeInterval
=
0.25
,
completion
:
(()
->
Void
)?
=
nil
)
{
let
animation
:
CABasicAnimation
=
CABasicAnimation
()
animation
.
keyPath
=
"cornerRadius"
animation
.
duration
=
duration
animation
.
toValue
=
radius
applyBasicAnimation
(
animation
,
layer
:
layer
,
completion
:
completion
)
}
/**
:name: applyBasicAnimation
*/
public
static
func
applyBasicAnimation
(
animation
:
CABasicAnimation
,
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
()
CATransaction
.
setDisableActions
(
true
)
CATransaction
.
setCompletionBlock
(
completion
)
if
let
v
=
animation
.
toValue
{
layer
.
setValue
(
v
,
forKey
:
animation
.
keyPath
!
)
}
else
if
let
v
=
animation
.
byValue
{
layer
.
setValue
(
v
,
forKey
:
animation
.
keyPath
!
)
}
CATransaction
.
commit
()
layer
.
addAnimation
(
animation
,
forKey
:
nil
)
}
/**
:name: disableAnimation
*/
public
static
func
disableAnimation
(
block
:
(()
->
Void
))
{
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0
)
block
()
CATransaction
.
commit
()
}
}
Source/MaterialButton.swift
View file @
68026aad
...
...
@@ -70,10 +70,10 @@ public class MaterialButton : UIButton {
*/
public
var
x
:
CGFloat
{
get
{
return
frame
.
origin
.
x
return
layer
.
frame
.
origin
.
x
}
set
(
value
)
{
frame
.
origin
.
x
=
value
layer
.
frame
.
origin
.
x
=
value
}
}
...
...
@@ -82,10 +82,10 @@ public class MaterialButton : UIButton {
*/
public
var
y
:
CGFloat
{
get
{
return
frame
.
origin
.
y
return
layer
.
frame
.
origin
.
y
}
set
(
value
)
{
frame
.
origin
.
y
=
value
layer
.
frame
.
origin
.
y
=
value
}
}
...
...
@@ -94,12 +94,12 @@ public class MaterialButton : UIButton {
*/
public
var
width
:
CGFloat
{
get
{
return
frame
.
size
.
width
return
layer
.
frame
.
size
.
width
}
set
(
value
)
{
frame
.
size
.
width
=
value
layer
.
frame
.
size
.
width
=
value
if
nil
!=
shape
{
frame
.
size
.
height
=
value
layer
.
frame
.
size
.
height
=
value
}
}
}
...
...
@@ -109,12 +109,12 @@ public class MaterialButton : UIButton {
*/
public
var
height
:
CGFloat
{
get
{
return
frame
.
size
.
height
return
layer
.
frame
.
size
.
height
}
set
(
value
)
{
frame
.
size
.
height
=
value
layer
.
frame
.
size
.
height
=
value
if
nil
!=
shape
{
frame
.
size
.
width
=
value
layer
.
frame
.
size
.
width
=
value
}
}
}
...
...
@@ -183,9 +183,9 @@ public class MaterialButton : UIButton {
didSet
{
if
nil
!=
shape
{
if
width
<
height
{
frame
.
size
.
width
=
height
layer
.
frame
.
size
.
width
=
height
}
else
{
frame
.
size
.
height
=
width
layer
.
frame
.
size
.
height
=
width
}
}
}
...
...
@@ -258,7 +258,7 @@ public class MaterialButton : UIButton {
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRect
Zero
)
self
.
init
(
frame
:
CGRect
Null
)
}
/**
...
...
@@ -288,23 +288,17 @@ public class MaterialButton : UIButton {
public
override
func
touchesBegan
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
let
point
:
CGPoint
=
touches
.
first
!.
locationInView
(
self
)
// set start position
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0
)
let
w
:
CGFloat
=
(
width
<
height
?
height
:
width
)
/
2
pulseLayer
.
hidden
=
false
pulseLayer
.
position
=
point
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
w
,
w
)
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
CATransaction
.
commit
()
// expand
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0.25
)
pulseLayer
.
transform
=
CATransform3DMakeScale
(
3
,
3
,
3
)
layer
.
transform
=
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
)
CATransaction
.
commit
()
MaterialAnimation
.
disableAnimation
({
_
in
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
w
,
w
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
})
pulseLayer
.
hidden
=
false
MaterialAnimation
.
transform
(
pulseLayer
,
scale
:
CATransform3DMakeScale
(
3
,
3
,
3
))
MaterialAnimation
.
transform
(
layer
,
scale
:
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
))
}
/**
...
...
@@ -368,11 +362,8 @@ public class MaterialButton : UIButton {
// :name: shrink
//
internal
func
shrink
()
{
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0.25
)
pulseLayer
.
hidden
=
true
pulseLayer
.
transform
=
CATransform3DIdentity
layer
.
transform
=
CATransform3DIdentity
CATransaction
.
commit
()
MaterialAnimation
.
transform
(
pulseLayer
,
scale
:
CATransform3DIdentity
)
MaterialAnimation
.
transform
(
layer
,
scale
:
CATransform3DIdentity
)
}
}
\ No newline at end of file
Source/MaterialLabel.swift
View file @
68026aad
...
...
@@ -157,7 +157,7 @@ public class MaterialLabel : UILabel {
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRect
Zero
)
self
.
init
(
frame
:
CGRect
Null
)
}
//
...
...
Source/MaterialPulseView.swift
View file @
68026aad
...
...
@@ -18,7 +18,7 @@
import
UIKit
public
class
MaterialPulseView
:
MaterialView
{
public
class
MaterialPulseView
:
MaterialView
{
//
// :name: touchesLayer
//
...
...
@@ -53,7 +53,7 @@ public class MaterialPulseView: MaterialView {
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRect
Zero
)
self
.
init
(
frame
:
CGRect
Null
)
}
/**
...
...
@@ -71,23 +71,17 @@ public class MaterialPulseView: MaterialView {
public
override
func
touchesBegan
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesBegan
(
touches
,
withEvent
:
event
)
let
point
:
CGPoint
=
touches
.
first
!.
locationInView
(
self
)
// set start position
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0
)
let
w
:
CGFloat
=
(
width
<
height
?
height
:
width
)
/
2
pulseLayer
.
hidden
=
false
pulseLayer
.
position
=
point
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
w
,
w
)
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
CATransaction
.
commit
()
// expand
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0.25
)
MaterialAnimation
.
disableAnimation
({
_
in
self
.
pulseLayer
.
bounds
=
CGRectMake
(
0
,
0
,
w
,
w
)
self
.
pulseLayer
.
position
=
point
self
.
pulseLayer
.
cornerRadius
=
CGFloat
(
w
/
2
)
})
pulseLayer
.
hidden
=
false
pulseLayer
.
transform
=
CATransform3DMakeScale
(
3
,
3
,
3
)
layer
.
transform
=
CATransform3DMakeScale
(
1.05
,
1.05
,
1.05
)
CATransaction
.
commit
()
}
/**
...
...
@@ -156,11 +150,8 @@ public class MaterialPulseView: MaterialView {
// :name: shrink
//
internal
func
shrink
()
{
CATransaction
.
begin
()
CATransaction
.
setAnimationDuration
(
0.25
)
pulseLayer
.
hidden
=
true
pulseLayer
.
transform
=
CATransform3DIdentity
layer
.
transform
=
CATransform3DIdentity
CATransaction
.
commit
()
}
}
Source/MaterialView.swift
View file @
68026aad
...
...
@@ -18,7 +18,7 @@
import
UIKit
public
class
MaterialView
:
UIView
{
public
class
MaterialView
:
UIView
{
//
// :name: visualLayer
//
...
...
@@ -86,10 +86,10 @@ public class MaterialView: UIView {
*/
public
var
x
:
CGFloat
{
get
{
return
frame
.
origin
.
x
return
layer
.
frame
.
origin
.
x
}
set
(
value
)
{
frame
.
origin
.
x
=
value
layer
.
frame
.
origin
.
x
=
value
}
}
...
...
@@ -98,10 +98,10 @@ public class MaterialView: UIView {
*/
public
var
y
:
CGFloat
{
get
{
return
frame
.
origin
.
y
return
layer
.
frame
.
origin
.
y
}
set
(
value
)
{
frame
.
origin
.
y
=
value
layer
.
frame
.
origin
.
y
=
value
}
}
...
...
@@ -110,12 +110,12 @@ public class MaterialView: UIView {
*/
public
var
width
:
CGFloat
{
get
{
return
frame
.
size
.
width
return
layer
.
frame
.
size
.
width
}
set
(
value
)
{
frame
.
size
.
width
=
value
layer
.
frame
.
size
.
width
=
value
if
nil
!=
shape
{
frame
.
size
.
height
=
value
layer
.
frame
.
size
.
height
=
value
}
}
}
...
...
@@ -125,12 +125,12 @@ public class MaterialView: UIView {
*/
public
var
height
:
CGFloat
{
get
{
return
frame
.
size
.
height
return
layer
.
frame
.
size
.
height
}
set
(
value
)
{
frame
.
size
.
height
=
value
layer
.
frame
.
size
.
height
=
value
if
nil
!=
shape
{
frame
.
size
.
width
=
value
layer
.
frame
.
size
.
width
=
value
}
}
}
...
...
@@ -199,9 +199,9 @@ public class MaterialView: UIView {
didSet
{
if
nil
!=
shape
{
if
width
<
height
{
frame
.
size
.
width
=
height
layer
.
frame
.
size
.
width
=
height
}
else
{
frame
.
size
.
height
=
width
layer
.
frame
.
size
.
height
=
width
}
}
}
...
...
@@ -265,7 +265,7 @@ public class MaterialView: UIView {
:name: init
*/
public
convenience
init
()
{
self
.
init
(
frame
:
CGRect
Zero
)
self
.
init
(
frame
:
CGRect
Null
)
}
/**
...
...
Source/NavigationBarView.swift
View file @
68026aad
...
...
@@ -18,7 +18,7 @@
import
UIKit
public
class
NavigationBarView
:
MaterialView
{
public
class
NavigationBarView
:
MaterialView
{
/**
:name: statusBarStyle
*/
...
...
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