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
6a1caacb
Commit
6a1caacb
authored
Oct 10, 2015
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated MaterialLayer and Material*Views internal animation logic
parent
e59a6f3e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
261 additions
and
9 deletions
+261
-9
Source/MaterialButton.swift
+0
-7
Source/MaterialLayer.swift
+260
-1
Source/MaterialTextLayer.swift
+1
-1
No files found.
Source/MaterialButton.swift
View file @
6a1caacb
...
...
@@ -439,13 +439,6 @@ public class MaterialButton : UIButton {
}
/**
: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
*/
public
func
prepareView
()
{
...
...
Source/MaterialLayer.swift
View file @
6a1caacb
...
...
@@ -18,26 +18,285 @@
import
UIKit
@objc(MaterialLayer)
public
class
MaterialLayer
:
CAShapeLayer
{
/**
:name: visualLayer
*/
public
private(set)
lazy
var
visualLayer
:
CAShapeLayer
=
CAShapeLayer
()
/**
:name: x
*/
public
var
x
:
CGFloat
{
get
{
return
frame
.
origin
.
x
}
set
(
value
)
{
frame
.
origin
.
x
=
value
}
}
/**
:name: y
*/
public
var
y
:
CGFloat
{
get
{
return
frame
.
origin
.
y
}
set
(
value
)
{
frame
.
origin
.
y
=
value
}
}
/**
:name: width
*/
public
var
width
:
CGFloat
{
get
{
return
frame
.
size
.
width
}
set
(
value
)
{
frame
.
size
.
width
=
value
if
.
None
!=
shape
{
frame
.
size
.
height
=
value
}
}
}
/**
:name: height
*/
public
var
height
:
CGFloat
{
get
{
return
frame
.
size
.
height
}
set
(
value
)
{
frame
.
size
.
height
=
value
if
.
None
!=
shape
{
frame
.
size
.
width
=
value
}
}
}
/**
:name: image
*/
public
var
image
:
UIImage
?
{
get
{
return
nil
==
visualLayer
.
contents
?
nil
:
UIImage
(
CGImage
:
visualLayer
.
contents
as!
CGImageRef
)
}
set
(
value
)
{
visualLayer
.
contents
=
value
?
.
CGImage
}
}
/**
:name: contentsRect
*/
public
override
var
contentsRect
:
CGRect
{
get
{
return
visualLayer
.
contentsRect
}
set
(
value
)
{
visualLayer
.
contentsRect
=
contentsRect
}
}
/**
:name: contentsCenter
*/
public
override
var
contentsCenter
:
CGRect
{
get
{
return
visualLayer
.
contentsCenter
}
set
(
value
)
{
visualLayer
.
contentsCenter
=
contentsCenter
}
}
/**
:name: contentsScale
*/
public
override
var
contentsScale
:
CGFloat
{
get
{
return
visualLayer
.
contentsScale
}
set
(
value
)
{
visualLayer
.
contentsScale
=
contentsScale
}
}
/**
:name: contentsGravity
*/
public
override
var
contentsGravity
:
String
{
get
{
return
visualLayer
.
contentsGravity
}
set
(
value
)
{
visualLayer
.
contentsGravity
=
value
}
}
/**
:name: masksToBounds
*/
public
override
var
masksToBounds
:
Bool
{
get
{
return
visualLayer
.
masksToBounds
}
set
(
value
)
{
visualLayer
.
masksToBounds
=
value
}
}
/**
:name: cornerRadius
*/
public
override
var
cornerRadius
:
CGFloat
{
get
{
return
visualLayer
.
cornerRadius
}
set
(
value
)
{
visualLayer
.
cornerRadius
=
value
if
.
Circle
==
shape
{
shape
=
.
None
}
}
}
/**
:name: shape
*/
public
var
shape
:
MaterialShape
{
didSet
{
if
.
None
!=
shape
{
if
width
<
height
{
width
=
height
}
else
{
height
=
width
}
}
}
}
/**
:name: shadowDepth
*/
public
var
shadowDepth
:
MaterialDepth
{
didSet
{
let
value
:
MaterialDepthType
=
MaterialDepthToValue
(
shadowDepth
)
shadowOffset
=
value
.
offset
shadowOpacity
=
value
.
opacity
shadowRadius
=
value
.
radius
}
}
/**
:name: init
*/
public
required
init
?(
coder
aDecoder
:
NSCoder
)
{
shape
=
.
None
shadowDepth
=
.
None
super
.
init
(
coder
:
aDecoder
)
prepareLayer
()
}
/**
:name: init
*/
public
override
init
(
layer
:
AnyObject
)
{
shape
=
.
None
shadowDepth
=
.
None
super
.
init
(
layer
:
layer
)
prepareLayer
()
}
/**
:name: init
*/
public
override
init
()
{
shape
=
.
None
shadowDepth
=
.
None
super
.
init
()
prepareLayer
()
}
/**
:name: init
*/
public
convenience
init
(
frame
:
CGRect
)
{
self
.
init
()
self
.
frame
=
frame
}
public
override
func
layoutSublayers
()
{
super
.
layoutSublayers
()
visualLayer
.
frame
=
bounds
visualLayer
.
position
=
CGPointMake
(
width
/
2
,
height
/
2
)
prepareShape
()
}
/**
: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
)
{
(
delegate
as?
MaterialAnimationDelegate
)?
.
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
!
)
})
}
(
delegate
as?
MaterialAnimationDelegate
)?
.
materialAnimationDidStop
?(
anim
,
finished
:
flag
)
removeAnimationForKey
(
a
.
keyPath
!
)
}
else
if
let
a
:
CAAnimationGroup
=
anim
as?
CAAnimationGroup
{
for
x
in
a
.
animations
!
{
animationDidStop
(
x
,
finished
:
true
)
}
}
}
/**
:name: prepareLayer
*/
public
func
prepareLayer
()
{
// visualLayer
masksToBounds
=
true
visualLayer
.
zPosition
=
-
1
addSublayer
(
visualLayer
)
}
//
// :name: prepareShape
//
internal
func
prepareShape
()
{
if
.
Circle
==
shape
{
cornerRadius
=
width
/
2
}
}
}
Source/MaterialTextLayer.swift
View file @
6a1caacb
...
...
@@ -154,7 +154,7 @@ public class MaterialTextLayer : CATextLayer {
:name: stringSize
*/
public
func
stringSize
(
constrainedToWidth
width
:
Double
)
->
CGSize
{
if
let
v
:
UIFont
=
internalFont
{
if
let
v
:
UIFont
=
internalFont
{
if
0
<
text
?
.
utf16
.
count
{
return
v
.
sizeOfString
(
text
!
,
constrainedToWidth
:
width
)
}
...
...
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