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
7b65a669
Commit
7b65a669
authored
May 01, 2016
by
Daniel Dahan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated pulse animations to a higher accuracy in the Material Design spec
parent
07d04f3f
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
135 additions
and
277 deletions
+135
-277
Examples/Programmatic/MaterialButton/MaterialButton.xcodeproj/project.pbxproj
+6
-0
Examples/Programmatic/MaterialButton/MaterialButton/ViewController.swift
+17
-6
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
+0
-6
Sources/iOS/FabButton.swift
+4
-1
Sources/iOS/FlatButton.swift
+0
-2
Sources/iOS/MaterialButton.swift
+14
-43
Sources/iOS/MaterialCollectionViewCell.swift
+13
-43
Sources/iOS/MaterialPulseAnimation.swift
+47
-79
Sources/iOS/MaterialPulseView.swift
+12
-38
Sources/iOS/MaterialTableViewCell.swift
+13
-43
Sources/iOS/MenuView.swift
+0
-1
Sources/iOS/NavigationBar.swift
+0
-1
Sources/iOS/RaisedButton.swift
+0
-2
Sources/iOS/SearchBar.swift
+0
-1
Sources/iOS/TextField.swift
+9
-11
No files found.
Examples/Programmatic/MaterialButton/MaterialButton.xcodeproj/project.pbxproj
View file @
7b65a669
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
objects
=
{
objects
=
{
/* Begin PBXBuildFile section */
/* Begin PBXBuildFile section */
9658F1F91CD6AA4900B902C1
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9658F1F81CD6AA4900B902C1
/* Material.framework */
;
};
9658F1FA1CD6AA4900B902C1
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9658F1F81CD6AA4900B902C1
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
965E8E721C14A4950035A270
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
965E8E711C14A4950035A270
/* AppDelegate.swift */
;
};
965E8E721C14A4950035A270
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
965E8E711C14A4950035A270
/* AppDelegate.swift */
;
};
965E8E741C14A4950035A270
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
965E8E731C14A4950035A270
/* ViewController.swift */
;
};
965E8E741C14A4950035A270
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
965E8E731C14A4950035A270
/* ViewController.swift */
;
};
965E8E791C14A4950035A270
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
965E8E781C14A4950035A270
/* Assets.xcassets */
;
};
965E8E791C14A4950035A270
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
965E8E781C14A4950035A270
/* Assets.xcassets */
;
};
...
@@ -20,6 +22,7 @@
...
@@ -20,6 +22,7 @@
dstPath
=
""
;
dstPath
=
""
;
dstSubfolderSpec
=
10
;
dstSubfolderSpec
=
10
;
files
=
(
files
=
(
9658F1FA1CD6AA4900B902C1
/* Material.framework in Embed Frameworks */
,
);
);
name
=
"Embed Frameworks"
;
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
runOnlyForDeploymentPostprocessing
=
0
;
...
@@ -27,6 +30,7 @@
...
@@ -27,6 +30,7 @@
/* End PBXCopyFilesBuildPhase section */
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
/* Begin PBXFileReference section */
9658F1F81CD6AA4900B902C1
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
Material.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphoneos/Material.framework"
;
sourceTree
=
"<absolute>"
;
};
965E8E6E1C14A4950035A270
/* MaterialButton.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
MaterialButton.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
965E8E6E1C14A4950035A270
/* MaterialButton.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
MaterialButton.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
965E8E711C14A4950035A270
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
965E8E711C14A4950035A270
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
965E8E731C14A4950035A270
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
965E8E731C14A4950035A270
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
...
@@ -40,6 +44,7 @@
...
@@ -40,6 +44,7 @@
isa
=
PBXFrameworksBuildPhase
;
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
buildActionMask
=
2147483647
;
files
=
(
files
=
(
9658F1F91CD6AA4900B902C1
/* Material.framework in Frameworks */
,
);
);
runOnlyForDeploymentPostprocessing
=
0
;
runOnlyForDeploymentPostprocessing
=
0
;
};
};
...
@@ -49,6 +54,7 @@
...
@@ -49,6 +54,7 @@
965E8E651C14A4950035A270
=
{
965E8E651C14A4950035A270
=
{
isa
=
PBXGroup
;
isa
=
PBXGroup
;
children
=
(
children
=
(
9658F1F81CD6AA4900B902C1
/* Material.framework */
,
965E8E701C14A4950035A270
/* MaterialButton */
,
965E8E701C14A4950035A270
/* MaterialButton */
,
965E8E6F1C14A4950035A270
/* Products */
,
965E8E6F1C14A4950035A270
/* Products */
,
);
);
...
...
Examples/Programmatic/MaterialButton/MaterialButton/ViewController.swift
View file @
7b65a669
...
@@ -45,6 +45,10 @@ class ViewController: UIViewController {
...
@@ -45,6 +45,10 @@ class ViewController: UIViewController {
prepareFabButtonExample
()
prepareFabButtonExample
()
}
}
override
func
viewDidAppear
(
animated
:
Bool
)
{
super
.
viewDidAppear
(
animated
)
}
/// General preparation statements.
/// General preparation statements.
private
func
prepareView
()
{
private
func
prepareView
()
{
view
.
backgroundColor
=
MaterialColor
.
white
view
.
backgroundColor
=
MaterialColor
.
white
...
@@ -52,9 +56,12 @@ class ViewController: UIViewController {
...
@@ -52,9 +56,12 @@ class ViewController: UIViewController {
/// Prepares the FlatButton.
/// Prepares the FlatButton.
private
func
prepareFlatButtonExample
()
{
private
func
prepareFlatButtonExample
()
{
let
button
:
FlatButton
=
FlatButton
(
frame
:
CGRectMake
(
107
,
107
,
200
,
65
))
let
w
:
CGFloat
=
200
let
button
:
FlatButton
=
FlatButton
(
frame
:
CGRectMake
((
view
.
bounds
.
width
-
w
)
/
2
,
100
,
w
,
48
))
button
.
setTitle
(
"Flat"
,
forState
:
.
Normal
)
button
.
setTitle
(
"Flat"
,
forState
:
.
Normal
)
button
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
32
)
button
.
setTitleColor
(
MaterialColor
.
blue
.
base
,
forState
:
.
Normal
)
button
.
pulseColor
=
MaterialColor
.
blue
.
base
button
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
24
)
// Add button to UIViewController.
// Add button to UIViewController.
view
.
addSubview
(
button
)
view
.
addSubview
(
button
)
...
@@ -62,9 +69,12 @@ class ViewController: UIViewController {
...
@@ -62,9 +69,12 @@ class ViewController: UIViewController {
/// Prepares the RaisedButton.
/// Prepares the RaisedButton.
private
func
prepareRaisedButtonExample
()
{
private
func
prepareRaisedButtonExample
()
{
let
button
:
RaisedButton
=
RaisedButton
(
frame
:
CGRectMake
(
107
,
207
,
200
,
65
))
let
w
:
CGFloat
=
200
let
button
:
RaisedButton
=
RaisedButton
(
frame
:
CGRectMake
((
view
.
bounds
.
width
-
w
)
/
2
,
200
,
w
,
48
))
button
.
setTitle
(
"Raised"
,
forState
:
.
Normal
)
button
.
setTitle
(
"Raised"
,
forState
:
.
Normal
)
button
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
32
)
button
.
setTitleColor
(
MaterialColor
.
blue
.
base
,
forState
:
.
Normal
)
button
.
pulseColor
=
MaterialColor
.
blue
.
base
button
.
titleLabel
!.
font
=
RobotoFont
.
mediumWithSize
(
24
)
// Add button to UIViewController.
// Add button to UIViewController.
view
.
addSubview
(
button
)
view
.
addSubview
(
button
)
...
@@ -72,8 +82,9 @@ class ViewController: UIViewController {
...
@@ -72,8 +82,9 @@ class ViewController: UIViewController {
/// Prepares the FabButton.
/// Prepares the FabButton.
private
func
prepareFabButtonExample
()
{
private
func
prepareFabButtonExample
()
{
let
img
:
UIImage
?
=
UIImage
(
named
:
"ic_create_white"
)
let
w
:
CGFloat
=
64
let
button
:
FabButton
=
FabButton
(
frame
:
CGRectMake
(
175
,
315
,
64
,
64
))
let
img
:
UIImage
?
=
MaterialIcon
.
cm
.
pen
let
button
:
FabButton
=
FabButton
(
frame
:
CGRectMake
((
view
.
bounds
.
width
-
w
)
/
2
,
300
,
w
,
64
))
button
.
setImage
(
img
,
forState
:
.
Normal
)
button
.
setImage
(
img
,
forState
:
.
Normal
)
button
.
setImage
(
img
,
forState
:
.
Highlighted
)
button
.
setImage
(
img
,
forState
:
.
Highlighted
)
...
...
Examples/Programmatic/TextField/TextField.xcodeproj/project.pbxproj
View file @
7b65a669
...
@@ -7,8 +7,6 @@
...
@@ -7,8 +7,6 @@
objects
=
{
objects
=
{
/* Begin PBXBuildFile section */
/* Begin PBXBuildFile section */
9658F1F01CD3C0EA00B902C1
/* Material.framework in Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9658F1EF1CD3C0EA00B902C1
/* Material.framework */
;
};
9658F1F11CD3C0EA00B902C1
/* Material.framework in Embed Frameworks */
=
{
isa
=
PBXBuildFile
;
fileRef
=
9658F1EF1CD3C0EA00B902C1
/* Material.framework */
;
settings
=
{
ATTRIBUTES
=
(
CodeSignOnCopy
,
RemoveHeadersOnCopy
,
);
};
};
966F57A11C226BAA009185B7
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A01C226BAA009185B7
/* AppDelegate.swift */
;
};
966F57A11C226BAA009185B7
/* AppDelegate.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A01C226BAA009185B7
/* AppDelegate.swift */
;
};
966F57A31C226BAA009185B7
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A21C226BAA009185B7
/* ViewController.swift */
;
};
966F57A31C226BAA009185B7
/* ViewController.swift in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A21C226BAA009185B7
/* ViewController.swift */
;
};
966F57A81C226BAA009185B7
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A71C226BAA009185B7
/* Assets.xcassets */
;
};
966F57A81C226BAA009185B7
/* Assets.xcassets in Resources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
966F57A71C226BAA009185B7
/* Assets.xcassets */
;
};
...
@@ -22,7 +20,6 @@
...
@@ -22,7 +20,6 @@
dstPath
=
""
;
dstPath
=
""
;
dstSubfolderSpec
=
10
;
dstSubfolderSpec
=
10
;
files
=
(
files
=
(
9658F1F11CD3C0EA00B902C1
/* Material.framework in Embed Frameworks */
,
);
);
name
=
"Embed Frameworks"
;
name
=
"Embed Frameworks"
;
runOnlyForDeploymentPostprocessing
=
0
;
runOnlyForDeploymentPostprocessing
=
0
;
...
@@ -30,7 +27,6 @@
...
@@ -30,7 +27,6 @@
/* End PBXCopyFilesBuildPhase section */
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
/* Begin PBXFileReference section */
9658F1EF1CD3C0EA00B902C1
/* Material.framework */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.framework
;
name
=
Material.framework
;
path
=
"/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphoneos/Material.framework"
;
sourceTree
=
"<absolute>"
;
};
966F579D1C226BAA009185B7
/* TextField.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
TextField.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
966F579D1C226BAA009185B7
/* TextField.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
TextField.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
966F57A01C226BAA009185B7
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
966F57A01C226BAA009185B7
/* AppDelegate.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
AppDelegate.swift
;
sourceTree
=
"<group>"
;
};
966F57A21C226BAA009185B7
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
966F57A21C226BAA009185B7
/* ViewController.swift */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.swift
;
path
=
ViewController.swift
;
sourceTree
=
"<group>"
;
};
...
@@ -44,7 +40,6 @@
...
@@ -44,7 +40,6 @@
isa
=
PBXFrameworksBuildPhase
;
isa
=
PBXFrameworksBuildPhase
;
buildActionMask
=
2147483647
;
buildActionMask
=
2147483647
;
files
=
(
files
=
(
9658F1F01CD3C0EA00B902C1
/* Material.framework in Frameworks */
,
);
);
runOnlyForDeploymentPostprocessing
=
0
;
runOnlyForDeploymentPostprocessing
=
0
;
};
};
...
@@ -54,7 +49,6 @@
...
@@ -54,7 +49,6 @@
966F57941C226BAA009185B7
=
{
966F57941C226BAA009185B7
=
{
isa
=
PBXGroup
;
isa
=
PBXGroup
;
children
=
(
children
=
(
9658F1EF1CD3C0EA00B902C1
/* Material.framework */
,
966F579F1C226BAA009185B7
/* TextField */
,
966F579F1C226BAA009185B7
/* TextField */
,
966F579E1C226BAA009185B7
/* Products */
,
966F579E1C226BAA009185B7
/* Products */
,
);
);
...
...
Sources/iOS/FabButton.swift
View file @
7b65a669
...
@@ -42,6 +42,8 @@ public class FabButton : MaterialButton {
...
@@ -42,6 +42,8 @@ public class FabButton : MaterialButton {
super
.
prepareView
()
super
.
prepareView
()
depth
=
.
Depth1
depth
=
.
Depth1
shape
=
.
Circle
shape
=
.
Circle
backgroundColor
=
MaterialColor
.
red
.
darken1
backgroundColor
=
MaterialColor
.
blue
.
base
pulseColor
=
MaterialColor
.
white
tintColor
=
MaterialColor
.
white
}
}
}
}
\ No newline at end of file
Sources/iOS/FlatButton.swift
View file @
7b65a669
...
@@ -42,6 +42,5 @@ public class FlatButton : MaterialButton {
...
@@ -42,6 +42,5 @@ public class FlatButton : MaterialButton {
super
.
prepareView
()
super
.
prepareView
()
cornerRadiusPreset
=
.
Radius1
cornerRadiusPreset
=
.
Radius1
contentEdgeInsetsPreset
=
.
WideRectangle3
contentEdgeInsetsPreset
=
.
WideRectangle3
pulseColor
=
MaterialColor
.
blue
.
accent3
}
}
}
}
\ No newline at end of file
Sources/iOS/MaterialButton.swift
View file @
7b65a669
...
@@ -46,24 +46,15 @@ public class MaterialButton : UIButton {
...
@@ -46,24 +46,15 @@ public class MaterialButton : UIButton {
*/
*/
public
weak
var
delegate
:
MaterialDelegate
?
public
weak
var
delegate
:
MaterialDelegate
?
/// To use a single pulse and have it focused when held.
/// An Array of pulse layers.
@IBInspectable
public
var
pulseFocus
:
Bool
=
false
public
private(set)
lazy
var
pulseLayers
:
Array
<
CAShapeLayer
>
=
Array
<
CAShapeLayer
>
()
/// A pulse layer for focus handling.
public
private(set)
var
pulseLayer
:
CAShapeLayer
?
/// Sets whether the scaling animation should be used.
@IBInspectable
public
lazy
var
pulseScale
:
Bool
=
true
/// The opacity value for the pulse animation.
/// The opacity value for the pulse animation.
@IBInspectable
public
var
pulseOpacity
:
CGFloat
=
0.
25
@IBInspectable
public
var
pulseOpacity
:
CGFloat
=
0.
12
/// The color of the pulse effect.
/// The color of the pulse effect.
@IBInspectable
public
var
pulseColor
:
UIColor
?
@IBInspectable
public
var
pulseColor
:
UIColor
?
/// Sets a pulse animation to always radiate from the center
@IBInspectable
public
var
pulseCenter
:
Bool
=
false
/**
/**
This property is the same as clipsToBounds. It crops any of the view's
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using
contents from bleeding past the view's frame. If an image is set using
...
@@ -412,20 +403,12 @@ public class MaterialButton : UIButton {
...
@@ -412,20 +403,12 @@ public class MaterialButton : UIButton {
*/
*/
public
func
pulse
(
point
:
CGPoint
?
=
nil
)
{
public
func
pulse
(
point
:
CGPoint
?
=
nil
)
{
let
p
:
CGPoint
=
nil
==
point
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
point
!
let
p
:
CGPoint
=
nil
==
point
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
point
!
let
duration
:
NSTimeInterval
=
MaterialAnimation
.
pulseDuration
(
width
)
if
let
color
:
UIColor
=
pulseColor
{
MaterialAnimation
.
pulseExpandAnimation
(
layer
,
visualLayer
:
visualLayer
,
pulseColor
:
pulseColor
,
pulseOpacity
:
pulseOpacity
,
point
:
p
,
width
:
width
,
height
:
height
,
pulseLayers
:
&
pulseLayers
)
if
let
v
:
UIColor
=
pulseColor
{
}
MaterialAnimation
.
pulseAnimation
(
layer
,
visualLayer
:
visualLayer
,
color
:
v
.
colorWithAlphaComponent
(
pulseOpacity
),
point
:
p
,
width
:
width
,
height
:
height
,
duration
:
duration
)
MaterialAnimation
.
delay
(
0.35
)
{
[
weak
self
]
in
}
if
let
s
:
MaterialButton
=
self
{
MaterialAnimation
.
pulseContractAnimation
(
s
.
layer
,
pulseColor
:
s
.
pulseColor
,
pulseLayers
:
&
s
.
pulseLayers
)
if
pulseScale
{
MaterialAnimation
.
expandAnimation
(
layer
,
scale
:
1.05
,
duration
:
duration
)
MaterialAnimation
.
delay
(
duration
)
{
[
weak
self
]
in
if
let
l
:
CALayer
=
self
?
.
layer
{
if
let
w
:
CGFloat
=
self
?
.
width
{
MaterialAnimation
.
shrinkAnimation
(
l
,
width
:
w
,
duration
:
duration
)
}
}
}
}
}
}
}
}
...
@@ -438,20 +421,7 @@ public class MaterialButton : UIButton {
...
@@ -438,20 +421,7 @@ 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
duration
:
NSTimeInterval
=
MaterialAnimation
.
pulseDuration
(
width
)
MaterialAnimation
.
pulseExpandAnimation
(
layer
,
visualLayer
:
visualLayer
,
pulseColor
:
pulseColor
,
pulseOpacity
:
pulseOpacity
,
point
:
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
),
width
:
width
,
height
:
height
,
pulseLayers
:
&
pulseLayers
)
if
pulseFocus
{
pulseLayer
=
CAShapeLayer
()
}
if
let
v
:
UIColor
=
pulseColor
{
let
point
:
CGPoint
=
pulseCenter
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
MaterialAnimation
.
pulseAnimation
(
layer
,
visualLayer
:
visualLayer
,
color
:
v
.
colorWithAlphaComponent
(
pulseOpacity
),
point
:
point
,
width
:
width
,
height
:
height
,
duration
:
duration
,
pulseLayer
:
pulseLayer
)
}
if
pulseScale
{
MaterialAnimation
.
expandAnimation
(
layer
,
scale
:
1.05
,
duration
:
duration
)
}
}
}
/**
/**
...
@@ -462,7 +432,7 @@ public class MaterialButton : UIButton {
...
@@ -462,7 +432,7 @@ public class MaterialButton : UIButton {
*/
*/
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
MaterialAnimation
.
shrinkAnimation
(
layer
,
width
:
width
,
duration
:
MaterialAnimation
.
pulseDuration
(
width
),
pulseLayer
:
pulseLayer
)
MaterialAnimation
.
pulseContractAnimation
(
layer
,
pulseColor
:
pulseColor
,
pulseLayers
:
&
pulseLayers
)
}
}
/**
/**
...
@@ -473,7 +443,7 @@ public class MaterialButton : UIButton {
...
@@ -473,7 +443,7 @@ public class MaterialButton : UIButton {
*/
*/
public
override
func
touchesCancelled
(
touches
:
Set
<
UITouch
>
?,
withEvent
event
:
UIEvent
?)
{
public
override
func
touchesCancelled
(
touches
:
Set
<
UITouch
>
?,
withEvent
event
:
UIEvent
?)
{
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
MaterialAnimation
.
shrinkAnimation
(
layer
,
width
:
width
,
duration
:
MaterialAnimation
.
pulseDuration
(
width
),
pulseLayer
:
pulseLayer
)
MaterialAnimation
.
pulseContractAnimation
(
layer
,
pulseColor
:
pulseColor
,
pulseLayers
:
&
pulseLayers
)
}
}
/**
/**
...
@@ -484,8 +454,9 @@ public class MaterialButton : UIButton {
...
@@ -484,8 +454,9 @@ public class MaterialButton : UIButton {
when subclassing.
when subclassing.
*/
*/
public
func
prepareView
()
{
public
func
prepareView
()
{
pulseColor
=
MaterialColor
.
black
contentScaleFactor
=
MaterialDevice
.
scale
prepareVisualLayer
()
prepareVisualLayer
()
pulseColor
=
MaterialColor
.
white
}
}
/// Prepares the visualLayer property.
/// Prepares the visualLayer property.
...
...
Sources/iOS/MaterialCollectionViewCell.swift
View file @
7b65a669
...
@@ -46,14 +46,8 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
...
@@ -46,14 +46,8 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/
*/
public
weak
var
delegate
:
MaterialDelegate
?
public
weak
var
delegate
:
MaterialDelegate
?
/// To use a single pulse and have it focused when held.
/// An Array of pulse layers.
@IBInspectable
public
var
pulseFocus
:
Bool
=
false
public
private(set)
lazy
var
pulseLayers
:
Array
<
CAShapeLayer
>
=
Array
<
CAShapeLayer
>
()
/// A pulse layer for focus handling.
public
private(set)
var
pulseLayer
:
CAShapeLayer
?
/// Sets whether the scaling animation should be used.
@IBInspectable
public
lazy
var
pulseScale
:
Bool
=
true
/// The opcaity value for the pulse animation.
/// The opcaity value for the pulse animation.
@IBInspectable
public
var
pulseOpacity
:
CGFloat
=
0.25
@IBInspectable
public
var
pulseOpacity
:
CGFloat
=
0.25
...
@@ -61,9 +55,6 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
...
@@ -61,9 +55,6 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
/// The color of the pulse effect.
/// The color of the pulse effect.
@IBInspectable
public
var
pulseColor
:
UIColor
?
@IBInspectable
public
var
pulseColor
:
UIColor
?
/// Sets a pulse animation to always radiate from the center
@IBInspectable
public
var
pulseCenter
:
Bool
=
false
/**
/**
A property that manages an image for the visualLayer's contents
A property that manages an image for the visualLayer's contents
property. Images should not be set to the backing layer's contents
property. Images should not be set to the backing layer's contents
...
@@ -517,20 +508,12 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
...
@@ -517,20 +508,12 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/
*/
public
func
pulse
(
point
:
CGPoint
?
=
nil
)
{
public
func
pulse
(
point
:
CGPoint
?
=
nil
)
{
let
p
:
CGPoint
=
nil
==
point
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
point
!
let
p
:
CGPoint
=
nil
==
point
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
point
!
let
duration
:
NSTimeInterval
=
MaterialAnimation
.
pulseDuration
(
width
)
if
let
color
:
UIColor
=
pulseColor
{
MaterialAnimation
.
pulseExpandAnimation
(
layer
,
visualLayer
:
visualLayer
,
pulseColor
:
pulseColor
,
pulseOpacity
:
pulseOpacity
,
point
:
p
,
width
:
width
,
height
:
height
,
pulseLayers
:
&
pulseLayers
)
if
let
v
:
UIColor
=
pulseColor
{
}
MaterialAnimation
.
pulseAnimation
(
layer
,
visualLayer
:
visualLayer
,
color
:
v
.
colorWithAlphaComponent
(
pulseOpacity
),
point
:
p
,
width
:
width
,
height
:
height
,
duration
:
duration
)
MaterialAnimation
.
delay
(
0.35
)
{
[
weak
self
]
in
}
if
let
s
:
MaterialCollectionViewCell
=
self
{
MaterialAnimation
.
pulseContractAnimation
(
s
.
layer
,
pulseColor
:
s
.
pulseColor
,
pulseLayers
:
&
s
.
pulseLayers
)
if
pulseScale
{
MaterialAnimation
.
expandAnimation
(
layer
,
scale
:
1.05
,
duration
:
duration
)
MaterialAnimation
.
delay
(
duration
)
{
[
weak
self
]
in
if
let
l
:
CALayer
=
self
?
.
layer
{
if
let
w
:
CGFloat
=
self
?
.
width
{
MaterialAnimation
.
shrinkAnimation
(
l
,
width
:
w
,
duration
:
duration
)
}
}
}
}
}
}
}
}
...
@@ -543,20 +526,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
...
@@ -543,20 +526,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/
*/
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
duration
:
NSTimeInterval
=
MaterialAnimation
.
pulseDuration
(
width
)
MaterialAnimation
.
pulseExpandAnimation
(
layer
,
visualLayer
:
visualLayer
,
pulseColor
:
pulseColor
,
pulseOpacity
:
pulseOpacity
,
point
:
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
),
width
:
width
,
height
:
height
,
pulseLayers
:
&
pulseLayers
)
if
pulseFocus
{
pulseLayer
=
CAShapeLayer
()
}
if
let
v
:
UIColor
=
pulseColor
{
let
point
:
CGPoint
=
pulseCenter
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
MaterialAnimation
.
pulseAnimation
(
layer
,
visualLayer
:
visualLayer
,
color
:
v
.
colorWithAlphaComponent
(
pulseOpacity
),
point
:
point
,
width
:
width
,
height
:
height
,
duration
:
duration
,
pulseLayer
:
pulseLayer
)
}
if
pulseScale
{
MaterialAnimation
.
expandAnimation
(
layer
,
scale
:
1.05
,
duration
:
duration
)
}
}
}
/**
/**
...
@@ -567,7 +537,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
...
@@ -567,7 +537,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/
*/
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
MaterialAnimation
.
shrinkAnimation
(
layer
,
width
:
width
,
duration
:
MaterialAnimation
.
pulseDuration
(
width
),
pulseLayer
:
pulseLayer
)
MaterialAnimation
.
pulseContractAnimation
(
layer
,
pulseColor
:
pulseColor
,
pulseLayers
:
&
pulseLayers
)
}
}
/**
/**
...
@@ -578,7 +548,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
...
@@ -578,7 +548,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
*/
*/
public
override
func
touchesCancelled
(
touches
:
Set
<
UITouch
>
?,
withEvent
event
:
UIEvent
?)
{
public
override
func
touchesCancelled
(
touches
:
Set
<
UITouch
>
?,
withEvent
event
:
UIEvent
?)
{
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
MaterialAnimation
.
shrinkAnimation
(
layer
,
width
:
width
,
duration
:
MaterialAnimation
.
pulseDuration
(
width
),
pulseLayer
:
pulseLayer
)
MaterialAnimation
.
pulseContractAnimation
(
layer
,
pulseColor
:
pulseColor
,
pulseLayers
:
&
pulseLayers
)
}
}
/**
/**
...
@@ -589,9 +559,9 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
...
@@ -589,9 +559,9 @@ public class MaterialCollectionViewCell : UICollectionViewCell {
when subclassing.
when subclassing.
*/
*/
public
func
prepareView
()
{
public
func
prepareView
()
{
pulseColor
=
MaterialColor
.
black
contentScaleFactor
=
MaterialDevice
.
scale
prepareVisualLayer
()
prepareVisualLayer
()
pulseColor
=
MaterialColor
.
grey
.
lighten1
pulseScale
=
false
}
}
/// Prepares the visualLayer property.
/// Prepares the visualLayer property.
...
...
Sources/iOS/MaterialPulseAnimation.swift
View file @
7b65a669
...
@@ -32,100 +32,69 @@ import UIKit
...
@@ -32,100 +32,69 @@ import UIKit
internal
extension
MaterialAnimation
{
internal
extension
MaterialAnimation
{
/**
/**
Triggers the
pulse
animation.
Triggers the
expanding
animation.
- Parameter layer: Container CALayer.
- Parameter layer: Container CALayer.
- Parameter visualLayer: A CAShapeLayer for the pulseLayer.
- Parameter visualLayer: A CAShapeLayer for the pulseLayer.
- Parameter
c
olor: The UIColor for the pulse.
- Parameter
pulseC
olor: The UIColor for the pulse.
- Parameter point: A point to pulse from.
- Parameter point: A point to pulse from.
- Parameter width: Container width.
- Parameter width: Container width.
- Parameter height: Container height.
- Parameter height: Container height.
- Parameter duration: Animation duration.
- Parameter duration: Animation duration.
- Parameter pulseLayer
: An Optional pulseLayer to use
in the animation.
- Parameter pulseLayer
s: An Array of CAShapeLayers used
in the animation.
*/
*/
internal
static
func
pulseAnimation
(
layer
:
CALayer
,
visualLayer
:
CALayer
,
color
:
UIColor
,
point
:
CGPoint
,
width
:
CGFloat
,
height
:
CGFloat
,
duration
:
NSTimeInterval
,
pulseLayer
:
CAShapeLayer
?
=
nil
)
{
internal
static
func
pulseExpandAnimation
(
layer
:
CALayer
,
visualLayer
:
CALayer
,
pulseColor
:
UIColor
?,
pulseOpacity
:
CGFloat
,
point
:
CGPoint
,
width
:
CGFloat
,
height
:
CGFloat
,
inout
pulseLayers
:
Array
<
CAShapeLayer
>
)
{
if
let
color
:
UIColor
=
pulseColor
{
let
r
:
CGFloat
=
(
width
<
height
?
height
:
width
)
/
2
if
let
n
:
CGFloat
=
width
<
height
?
height
:
width
{
let
f
:
CGFloat
=
3
if
let
pOpacity
:
CGFloat
=
pulseOpacity
{
let
v
:
CGFloat
=
r
/
f
let
bLayer
:
CAShapeLayer
=
CAShapeLayer
()
let
d
:
CGFloat
=
2
*
f
let
pLayer
:
CAShapeLayer
=
CAShapeLayer
()
bLayer
.
addSublayer
(
pLayer
)
var
b
:
Bool
=
false
pulseLayers
.
insert
(
bLayer
,
atIndex
:
0
)
var
pLayer
:
CAShapeLayer
?
visualLayer
.
insertSublayer
(
bLayer
,
atIndex
:
0
)
MaterialAnimation
.
animationDisabled
({
if
nil
==
pulseLayer
{
bLayer
.
frame
=
visualLayer
.
bounds
pLayer
=
CAShapeLayer
()
pLayer
.
bounds
=
CGRectMake
(
0
,
0
,
n
,
n
)
b
=
true
pLayer
.
position
=
point
}
else
{
pLayer
.
cornerRadius
=
n
/
2
pLayer
=
pulseLayer
pLayer
.
backgroundColor
=
color
.
colorWithAlphaComponent
(
pOpacity
)
.
CGColor
}
pLayer
.
transform
=
CATransform3DMakeAffineTransform
(
CGAffineTransformMakeScale
(
0
,
0
))
})
pLayer
!.
hidden
=
true
bLayer
.
setValue
(
false
,
forKey
:
"animated"
)
pLayer
!.
zPosition
=
1
bLayer
.
addAnimation
(
MaterialAnimation
.
backgroundColor
(
color
.
colorWithAlphaComponent
(
pOpacity
/
2
),
duration
:
0.35
),
forKey
:
nil
)
pLayer
!.
backgroundColor
=
color
.
CGColor
pLayer
.
addAnimation
(
MaterialAnimation
.
scale
(
1
,
duration
:
0.35
),
forKey
:
nil
)
visualLayer
.
addSublayer
(
pLayer
!
)
MaterialAnimation
.
delay
(
0.35
,
completion
:
{
bLayer
.
setValue
(
true
,
forKey
:
"animated"
)
MaterialAnimation
.
animationDisabled
{
})
pLayer
!.
bounds
=
CGRectMake
(
0
,
0
,
v
,
v
)
pLayer
!.
position
=
point
pLayer
!.
cornerRadius
=
r
/
d
pLayer
!.
hidden
=
false
}
pLayer
!.
addAnimation
(
MaterialAnimation
.
scale
((
b
?
3
:
1.7
)
*
d
,
duration
:
duration
),
forKey
:
nil
)
if
b
{
MaterialAnimation
.
delay
(
duration
)
{
MaterialAnimation
.
animateWithDuration
(
duration
,
animations
:
{
pLayer
?
.
hidden
=
true
})
{
pLayer
?
.
removeFromSuperlayer
()
}
}
}
}
}
else
{
MaterialAnimation
.
delay
(
duration
/
2
)
{
pLayer
?
.
addAnimation
(
MaterialAnimation
.
scale
(
1.3
*
d
,
duration
:
duration
),
forKey
:
nil
)
}
}
}
}
}
/**
/**
Triggers the expanding animation.
Triggers the contracting animation.
- Parameter layer: Container CALayer.
- Parameter scale: The scale factor when expanding.
- Parameter duration: Animation duration.
*/
internal
static
func
expandAnimation
(
layer
:
CALayer
,
scale
:
CGFloat
,
duration
:
NSTimeInterval
)
{
layer
.
addAnimation
(
MaterialAnimation
.
scale
(
scale
,
duration
:
duration
),
forKey
:
nil
)
}
/**
Triggers the shrinking animation.
- Parameter layer: Container CALayer.
- Parameter layer: Container CALayer.
- Parameter width: Container width.
- Parameter pulseColor: The UIColor for the pulse.
- Parameter duration: Animation duration.
- Parameter pulseLayers: An Array of CAShapeLayers used in the animation.
- Parameter pulseLayer: An Optional pulseLayer to use in the animation.
*/
*/
internal
static
func
shrinkAnimation
(
layer
:
CALayer
,
width
:
CGFloat
,
duration
:
NSTimeInterval
,
pulseLayer
:
CAShapeLayer
?
=
nil
)
{
internal
static
func
pulseContractAnimation
(
layer
:
CALayer
,
pulseColor
:
UIColor
?,
inout
pulseLayers
:
Array
<
CAShapeLayer
>
)
{
if
let
v
:
CAShapeLayer
=
pulseLayer
{
if
let
color
:
UIColor
=
pulseColor
{
MaterialAnimation
.
animateWithDuration
(
duration
,
animations
:
{
if
let
bLayer
:
CAShapeLayer
=
pulseLayers
.
popLast
()
{
v
.
hidden
=
true
let
animated
:
Bool
?
=
bLayer
.
valueForKey
(
"animated"
)
as?
Bool
})
{
MaterialAnimation
.
delay
(
true
==
animated
?
0
:
0.10
)
{
v
.
removeFromSuperlayer
()
if
let
pLayer
:
CAShapeLayer
=
bLayer
.
sublayers
?
.
first
as?
CAShapeLayer
{
bLayer
.
addAnimation
(
MaterialAnimation
.
backgroundColor
(
color
.
colorWithAlphaComponent
(
0
),
duration
:
0.35
),
forKey
:
nil
)
pLayer
.
addAnimation
(
MaterialAnimation
.
animationGroup
([
MaterialAnimation
.
scale
(
1.35
),
MaterialAnimation
.
backgroundColor
(
color
.
colorWithAlphaComponent
(
0
))
],
duration
:
0.35
),
forKey
:
nil
)
MaterialAnimation
.
delay
(
0.35
)
{
pLayer
.
removeFromSuperlayer
()
bLayer
.
removeFromSuperlayer
()
}
}
}
}
}
}
}
layer
.
addAnimation
(
MaterialAnimation
.
scale
(
1
,
duration
:
duration
),
forKey
:
nil
)
}
/**
Retrieves the animation duration time.
- Parameter width: Container width.
- Returns: An NSTimeInterval value that represents the animation time.
*/
internal
static
func
pulseDuration
(
width
:
CGFloat
)
->
NSTimeInterval
{
var
t
:
CFTimeInterval
=
CFTimeInterval
(
1.5
*
width
/
MaterialDevice
.
width
)
if
0.55
<
t
||
0.25
>
t
{
t
=
0.55
}
return
t
/
1.3
}
}
}
}
\ No newline at end of file
Sources/iOS/MaterialPulseView.swift
View file @
7b65a669
...
@@ -34,11 +34,8 @@ public class MaterialPulseView : MaterialView {
...
@@ -34,11 +34,8 @@ public class MaterialPulseView : MaterialView {
/// To use a single pulse and have it focused when held.
/// To use a single pulse and have it focused when held.
@IBInspectable
public
var
pulseFocus
:
Bool
=
false
@IBInspectable
public
var
pulseFocus
:
Bool
=
false
/// A pulse layer for focus handling.
/// An Array of pulse layers.
public
private(set)
var
pulseLayer
:
CAShapeLayer
?
public
private(set)
lazy
var
pulseLayers
:
Array
<
CAShapeLayer
>
=
Array
<
CAShapeLayer
>
()
/// Sets whether the scaling animation should be used.
@IBInspectable
public
lazy
var
pulseScale
:
Bool
=
true
/// The opcaity value for the pulse animation.
/// The opcaity value for the pulse animation.
@IBInspectable
public
var
pulseOpacity
:
CGFloat
=
0.25
@IBInspectable
public
var
pulseOpacity
:
CGFloat
=
0.25
...
@@ -46,9 +43,6 @@ public class MaterialPulseView : MaterialView {
...
@@ -46,9 +43,6 @@ public class MaterialPulseView : MaterialView {
/// The color of the pulse effect.
/// The color of the pulse effect.
@IBInspectable
public
var
pulseColor
:
UIColor
?
@IBInspectable
public
var
pulseColor
:
UIColor
?
/// Sets a pulse animation to always radiate from the center
@IBInspectable
public
var
pulseCenter
:
Bool
=
false
/**
/**
Triggers the pulse animation.
Triggers the pulse animation.
- Parameter point: A Optional point to pulse from, otherwise pulses
- Parameter point: A Optional point to pulse from, otherwise pulses
...
@@ -56,20 +50,12 @@ public class MaterialPulseView : MaterialView {
...
@@ -56,20 +50,12 @@ public class MaterialPulseView : MaterialView {
*/
*/
public
func
pulse
(
point
:
CGPoint
?
=
nil
)
{
public
func
pulse
(
point
:
CGPoint
?
=
nil
)
{
let
p
:
CGPoint
=
nil
==
point
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
point
!
let
p
:
CGPoint
=
nil
==
point
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
point
!
let
duration
:
NSTimeInterval
=
MaterialAnimation
.
pulseDuration
(
width
)
if
let
color
:
UIColor
=
pulseColor
{
MaterialAnimation
.
pulseExpandAnimation
(
layer
,
visualLayer
:
visualLayer
,
pulseColor
:
pulseColor
,
pulseOpacity
:
pulseOpacity
,
point
:
p
,
width
:
width
,
height
:
height
,
pulseLayers
:
&
pulseLayers
)
if
let
v
:
UIColor
=
pulseColor
{
MaterialAnimation
.
pulseAnimation
(
layer
,
visualLayer
:
visualLayer
,
color
:
v
.
colorWithAlphaComponent
(
pulseOpacity
),
point
:
p
,
width
:
width
,
height
:
height
,
duration
:
duration
)
}
}
MaterialAnimation
.
delay
(
0.35
)
{
[
weak
self
]
in
if
pulseScale
{
if
let
s
:
MaterialPulseView
=
self
{
MaterialAnimation
.
expandAnimation
(
layer
,
scale
:
1.05
,
duration
:
duration
)
MaterialAnimation
.
pulseContractAnimation
(
s
.
layer
,
pulseColor
:
s
.
pulseColor
,
pulseLayers
:
&
s
.
pulseLayers
)
MaterialAnimation
.
delay
(
duration
)
{
[
weak
self
]
in
if
let
l
:
CALayer
=
self
?
.
layer
{
if
let
w
:
CGFloat
=
self
?
.
width
{
MaterialAnimation
.
shrinkAnimation
(
l
,
width
:
w
,
duration
:
duration
)
}
}
}
}
}
}
}
}
...
@@ -82,20 +68,7 @@ public class MaterialPulseView : MaterialView {
...
@@ -82,20 +68,7 @@ public class MaterialPulseView : MaterialView {
*/
*/
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
duration
:
NSTimeInterval
=
MaterialAnimation
.
pulseDuration
(
width
)
MaterialAnimation
.
pulseExpandAnimation
(
layer
,
visualLayer
:
visualLayer
,
pulseColor
:
pulseColor
,
pulseOpacity
:
pulseOpacity
,
point
:
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
),
width
:
width
,
height
:
height
,
pulseLayers
:
&
pulseLayers
)
if
pulseFocus
{
pulseLayer
=
CAShapeLayer
()
}
if
let
v
:
UIColor
=
pulseColor
{
let
point
:
CGPoint
=
pulseCenter
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
MaterialAnimation
.
pulseAnimation
(
layer
,
visualLayer
:
visualLayer
,
color
:
v
.
colorWithAlphaComponent
(
pulseOpacity
),
point
:
point
,
width
:
width
,
height
:
height
,
duration
:
duration
,
pulseLayer
:
pulseLayer
)
}
if
pulseScale
{
MaterialAnimation
.
expandAnimation
(
layer
,
scale
:
1.05
,
duration
:
duration
)
}
}
}
/**
/**
...
@@ -106,7 +79,7 @@ public class MaterialPulseView : MaterialView {
...
@@ -106,7 +79,7 @@ public class MaterialPulseView : MaterialView {
*/
*/
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
MaterialAnimation
.
shrinkAnimation
(
layer
,
width
:
width
,
duration
:
MaterialAnimation
.
pulseDuration
(
width
),
pulseLayer
:
pulseLayer
)
MaterialAnimation
.
pulseContractAnimation
(
layer
,
pulseColor
:
pulseColor
,
pulseLayers
:
&
pulseLayers
)
}
}
/**
/**
...
@@ -117,7 +90,7 @@ public class MaterialPulseView : MaterialView {
...
@@ -117,7 +90,7 @@ public class MaterialPulseView : MaterialView {
*/
*/
public
override
func
touchesCancelled
(
touches
:
Set
<
UITouch
>
?,
withEvent
event
:
UIEvent
?)
{
public
override
func
touchesCancelled
(
touches
:
Set
<
UITouch
>
?,
withEvent
event
:
UIEvent
?)
{
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
MaterialAnimation
.
shrinkAnimation
(
layer
,
width
:
width
,
duration
:
MaterialAnimation
.
pulseDuration
(
width
),
pulseLayer
:
pulseLayer
)
MaterialAnimation
.
pulseContractAnimation
(
layer
,
pulseColor
:
pulseColor
,
pulseLayers
:
&
pulseLayers
)
}
}
/**
/**
...
@@ -129,6 +102,7 @@ public class MaterialPulseView : MaterialView {
...
@@ -129,6 +102,7 @@ public class MaterialPulseView : MaterialView {
*/
*/
public
override
func
prepareView
()
{
public
override
func
prepareView
()
{
super
.
prepareView
()
super
.
prepareView
()
pulseColor
=
MaterialColor
.
white
pulseColor
=
MaterialColor
.
black
contentScaleFactor
=
MaterialDevice
.
scale
}
}
}
}
Sources/iOS/MaterialTableViewCell.swift
View file @
7b65a669
...
@@ -45,14 +45,8 @@ public class MaterialTableViewCell : UITableViewCell {
...
@@ -45,14 +45,8 @@ public class MaterialTableViewCell : UITableViewCell {
*/
*/
public
weak
var
delegate
:
MaterialDelegate
?
public
weak
var
delegate
:
MaterialDelegate
?
/// To use a single pulse and have it focused when held.
/// An Array of pulse layers.
@IBInspectable
public
var
pulseFocus
:
Bool
=
false
public
private(set)
lazy
var
pulseLayers
:
Array
<
CAShapeLayer
>
=
Array
<
CAShapeLayer
>
()
/// A pulse layer for focus handling.
public
private(set)
var
pulseLayer
:
CAShapeLayer
?
/// Sets whether the scaling animation should be used.
@IBInspectable
public
lazy
var
pulseScale
:
Bool
=
true
/// The opcaity value for the pulse animation.
/// The opcaity value for the pulse animation.
@IBInspectable
public
var
pulseOpacity
:
CGFloat
=
0.25
@IBInspectable
public
var
pulseOpacity
:
CGFloat
=
0.25
...
@@ -60,9 +54,6 @@ public class MaterialTableViewCell : UITableViewCell {
...
@@ -60,9 +54,6 @@ public class MaterialTableViewCell : UITableViewCell {
/// The color of the pulse effect.
/// The color of the pulse effect.
@IBInspectable
public
var
pulseColor
:
UIColor
?
@IBInspectable
public
var
pulseColor
:
UIColor
?
/// Sets a pulse animation to always radiate from the center
@IBInspectable
public
var
pulseCenter
:
Bool
=
false
/**
/**
This property is the same as clipsToBounds. It crops any of the view's
This property is the same as clipsToBounds. It crops any of the view's
contents from bleeding past the view's frame. If an image is set using
contents from bleeding past the view's frame. If an image is set using
...
@@ -367,20 +358,12 @@ public class MaterialTableViewCell : UITableViewCell {
...
@@ -367,20 +358,12 @@ public class MaterialTableViewCell : UITableViewCell {
*/
*/
public
func
pulse
(
point
:
CGPoint
?
=
nil
)
{
public
func
pulse
(
point
:
CGPoint
?
=
nil
)
{
let
p
:
CGPoint
=
nil
==
point
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
point
!
let
p
:
CGPoint
=
nil
==
point
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
point
!
let
duration
:
NSTimeInterval
=
MaterialAnimation
.
pulseDuration
(
width
)
if
let
color
:
UIColor
=
pulseColor
{
MaterialAnimation
.
pulseExpandAnimation
(
layer
,
visualLayer
:
visualLayer
,
pulseColor
:
pulseColor
,
pulseOpacity
:
pulseOpacity
,
point
:
p
,
width
:
width
,
height
:
height
,
pulseLayers
:
&
pulseLayers
)
if
let
v
:
UIColor
=
pulseColor
{
}
MaterialAnimation
.
pulseAnimation
(
layer
,
visualLayer
:
visualLayer
,
color
:
v
.
colorWithAlphaComponent
(
pulseOpacity
),
point
:
p
,
width
:
width
,
height
:
height
,
duration
:
duration
)
MaterialAnimation
.
delay
(
0.35
)
{
[
weak
self
]
in
}
if
let
s
:
MaterialTableViewCell
=
self
{
MaterialAnimation
.
pulseContractAnimation
(
s
.
layer
,
pulseColor
:
s
.
pulseColor
,
pulseLayers
:
&
s
.
pulseLayers
)
if
pulseScale
{
MaterialAnimation
.
expandAnimation
(
layer
,
scale
:
1.05
,
duration
:
duration
)
MaterialAnimation
.
delay
(
duration
)
{
[
weak
self
]
in
if
let
l
:
CALayer
=
self
?
.
layer
{
if
let
w
:
CGFloat
=
self
?
.
width
{
MaterialAnimation
.
shrinkAnimation
(
l
,
width
:
w
,
duration
:
duration
)
}
}
}
}
}
}
}
}
...
@@ -393,20 +376,7 @@ public class MaterialTableViewCell : UITableViewCell {
...
@@ -393,20 +376,7 @@ public class MaterialTableViewCell : UITableViewCell {
*/
*/
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
duration
:
NSTimeInterval
=
MaterialAnimation
.
pulseDuration
(
width
)
MaterialAnimation
.
pulseExpandAnimation
(
layer
,
visualLayer
:
visualLayer
,
pulseColor
:
pulseColor
,
pulseOpacity
:
pulseOpacity
,
point
:
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
),
width
:
width
,
height
:
height
,
pulseLayers
:
&
pulseLayers
)
if
pulseFocus
{
pulseLayer
=
CAShapeLayer
()
}
if
let
v
:
UIColor
=
pulseColor
{
let
point
:
CGPoint
=
pulseCenter
?
CGPointMake
(
CGFloat
(
width
/
2
),
CGFloat
(
height
/
2
))
:
layer
.
convertPoint
(
touches
.
first
!.
locationInView
(
self
),
fromLayer
:
layer
)
MaterialAnimation
.
pulseAnimation
(
layer
,
visualLayer
:
visualLayer
,
color
:
v
.
colorWithAlphaComponent
(
pulseOpacity
),
point
:
point
,
width
:
width
,
height
:
height
,
duration
:
duration
,
pulseLayer
:
pulseLayer
)
}
if
pulseScale
{
MaterialAnimation
.
expandAnimation
(
layer
,
scale
:
1.05
,
duration
:
duration
)
}
}
}
/**
/**
...
@@ -417,7 +387,7 @@ public class MaterialTableViewCell : UITableViewCell {
...
@@ -417,7 +387,7 @@ public class MaterialTableViewCell : UITableViewCell {
*/
*/
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
public
override
func
touchesEnded
(
touches
:
Set
<
UITouch
>
,
withEvent
event
:
UIEvent
?)
{
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
super
.
touchesEnded
(
touches
,
withEvent
:
event
)
MaterialAnimation
.
shrinkAnimation
(
layer
,
width
:
width
,
duration
:
MaterialAnimation
.
pulseDuration
(
width
),
pulseLayer
:
pulseLayer
)
MaterialAnimation
.
pulseContractAnimation
(
layer
,
pulseColor
:
pulseColor
,
pulseLayers
:
&
pulseLayers
)
}
}
/**
/**
...
@@ -428,7 +398,7 @@ public class MaterialTableViewCell : UITableViewCell {
...
@@ -428,7 +398,7 @@ public class MaterialTableViewCell : UITableViewCell {
*/
*/
public
override
func
touchesCancelled
(
touches
:
Set
<
UITouch
>
?,
withEvent
event
:
UIEvent
?)
{
public
override
func
touchesCancelled
(
touches
:
Set
<
UITouch
>
?,
withEvent
event
:
UIEvent
?)
{
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
super
.
touchesCancelled
(
touches
,
withEvent
:
event
)
MaterialAnimation
.
shrinkAnimation
(
layer
,
width
:
width
,
duration
:
MaterialAnimation
.
pulseDuration
(
width
),
pulseLayer
:
pulseLayer
)
MaterialAnimation
.
pulseContractAnimation
(
layer
,
pulseColor
:
pulseColor
,
pulseLayers
:
&
pulseLayers
)
}
}
/**
/**
...
@@ -441,8 +411,8 @@ public class MaterialTableViewCell : UITableViewCell {
...
@@ -441,8 +411,8 @@ public class MaterialTableViewCell : UITableViewCell {
public
func
prepareView
()
{
public
func
prepareView
()
{
prepareVisualLayer
()
prepareVisualLayer
()
selectionStyle
=
.
None
selectionStyle
=
.
None
pulseColor
=
MaterialColor
.
grey
.
lighten1
pulseColor
=
MaterialColor
.
black
pulseScale
=
fals
e
contentScaleFactor
=
MaterialDevice
.
scal
e
imageView
?
.
userInteractionEnabled
=
false
imageView
?
.
userInteractionEnabled
=
false
textLabel
?
.
userInteractionEnabled
=
false
textLabel
?
.
userInteractionEnabled
=
false
detailTextLabel
?
.
userInteractionEnabled
=
false
detailTextLabel
?
.
userInteractionEnabled
=
false
...
...
Sources/iOS/MenuView.swift
View file @
7b65a669
...
@@ -44,7 +44,6 @@ public class MenuView : MaterialPulseView {
...
@@ -44,7 +44,6 @@ public class MenuView : MaterialPulseView {
public
override
func
prepareView
()
{
public
override
func
prepareView
()
{
super
.
prepareView
()
super
.
prepareView
()
pulseColor
=
nil
pulseColor
=
nil
pulseScale
=
false
clipsToBounds
=
false
clipsToBounds
=
false
backgroundColor
=
nil
backgroundColor
=
nil
}
}
...
...
Sources/iOS/NavigationBar.swift
View file @
7b65a669
...
@@ -407,7 +407,6 @@ public class NavigationBar : UINavigationBar {
...
@@ -407,7 +407,6 @@ public class NavigationBar : UINavigationBar {
/// Prepares the backButton.
/// Prepares the backButton.
internal
func
prepareBackButton
()
{
internal
func
prepareBackButton
()
{
backButton
.
pulseScale
=
false
backButton
.
pulseColor
=
MaterialColor
.
white
backButton
.
pulseColor
=
MaterialColor
.
white
backButton
.
setImage
(
backButtonImage
,
forState
:
.
Normal
)
backButton
.
setImage
(
backButtonImage
,
forState
:
.
Normal
)
backButton
.
setImage
(
backButtonImage
,
forState
:
.
Highlighted
)
backButton
.
setImage
(
backButtonImage
,
forState
:
.
Highlighted
)
...
...
Sources/iOS/RaisedButton.swift
View file @
7b65a669
...
@@ -44,6 +44,5 @@ public class RaisedButton : MaterialButton {
...
@@ -44,6 +44,5 @@ public class RaisedButton : MaterialButton {
cornerRadiusPreset
=
.
Radius1
cornerRadiusPreset
=
.
Radius1
contentEdgeInsetsPreset
=
.
WideRectangle3
contentEdgeInsetsPreset
=
.
WideRectangle3
backgroundColor
=
MaterialColor
.
white
backgroundColor
=
MaterialColor
.
white
pulseColor
=
MaterialColor
.
blue
.
accent3
}
}
}
}
\ No newline at end of file
Sources/iOS/SearchBar.swift
View file @
7b65a669
...
@@ -130,7 +130,6 @@ public class SearchBar : StatusBarView {
...
@@ -130,7 +130,6 @@ public class SearchBar : StatusBarView {
clearButton
.
contentEdgeInsets
=
UIEdgeInsetsZero
clearButton
.
contentEdgeInsets
=
UIEdgeInsetsZero
clearButton
.
pulseColor
=
MaterialColor
.
black
clearButton
.
pulseColor
=
MaterialColor
.
black
clearButton
.
pulseOpacity
=
0.12
clearButton
.
pulseOpacity
=
0.12
clearButton
.
pulseScale
=
false
clearButton
.
tintColor
=
placeholderTextColor
clearButton
.
tintColor
=
placeholderTextColor
clearButton
.
setImage
(
image
,
forState
:
.
Normal
)
clearButton
.
setImage
(
image
,
forState
:
.
Normal
)
clearButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
clearButton
.
setImage
(
image
,
forState
:
.
Highlighted
)
...
...
Sources/iOS/TextField.swift
View file @
7b65a669
...
@@ -152,14 +152,14 @@ public class TextField : UITextField {
...
@@ -152,14 +152,14 @@ public class TextField : UITextField {
}
}
}
}
/// TextField's text property observer.
/// TextField's text property observer.
public
override
var
text
:
String
?
{
@IBInspectable
public
override
var
text
:
String
?
{
didSet
{
didSet
{
if
(
text
==
nil
||
text
!.
isEmpty
)
&&
!
self
.
isFirstResponder
()
{
if
(
nil
==
text
||
text
!.
isEmpty
)
&&
!
isFirstResponder
()
{
placeholderEditingDidEndAnimation
()
placeholderEditingDidEndAnimation
()
}
}
}
}
}
}
/// The placeholderLabel text value.
/// The placeholderLabel text value.
@IBInspectable
public
override
var
placeholder
:
String
?
{
@IBInspectable
public
override
var
placeholder
:
String
?
{
...
@@ -255,7 +255,6 @@ public class TextField : UITextField {
...
@@ -255,7 +255,6 @@ public class TextField : UITextField {
clearFlatButton
=
FlatButton
(
frame
:
CGRectZero
)
clearFlatButton
=
FlatButton
(
frame
:
CGRectZero
)
clearFlatButton
!.
contentEdgeInsets
=
UIEdgeInsetsZero
clearFlatButton
!.
contentEdgeInsets
=
UIEdgeInsetsZero
clearFlatButton
!.
pulseColor
=
nil
clearFlatButton
!.
pulseColor
=
nil
clearFlatButton
!.
pulseScale
=
false
clearFlatButton
!.
tintColor
=
placeholderColor
clearFlatButton
!.
tintColor
=
placeholderColor
clearFlatButton
!.
setImage
(
image
,
forState
:
.
Normal
)
clearFlatButton
!.
setImage
(
image
,
forState
:
.
Normal
)
clearFlatButton
!.
setImage
(
image
,
forState
:
.
Highlighted
)
clearFlatButton
!.
setImage
(
image
,
forState
:
.
Highlighted
)
...
@@ -293,7 +292,6 @@ public class TextField : UITextField {
...
@@ -293,7 +292,6 @@ public class TextField : UITextField {
visibilityFlatButton
=
FlatButton
(
frame
:
CGRectZero
)
visibilityFlatButton
=
FlatButton
(
frame
:
CGRectZero
)
visibilityFlatButton
!.
contentEdgeInsets
=
UIEdgeInsetsZero
visibilityFlatButton
!.
contentEdgeInsets
=
UIEdgeInsetsZero
visibilityFlatButton
!.
pulseColor
=
nil
visibilityFlatButton
!.
pulseColor
=
nil
visibilityFlatButton
!.
pulseScale
=
false
visibilityFlatButton
!.
tintColor
=
placeholderColor
visibilityFlatButton
!.
tintColor
=
placeholderColor
visibilityFlatButton
!.
setImage
(
image
,
forState
:
.
Normal
)
visibilityFlatButton
!.
setImage
(
image
,
forState
:
.
Normal
)
visibilityFlatButton
!.
setImage
(
image
,
forState
:
.
Highlighted
)
visibilityFlatButton
!.
setImage
(
image
,
forState
:
.
Highlighted
)
...
@@ -516,7 +514,7 @@ public class TextField : UITextField {
...
@@ -516,7 +514,7 @@ public class TextField : UITextField {
/// Layout the detailLabel.
/// Layout the detailLabel.
public
func
layoutDetailLabel
()
{
public
func
layoutDetailLabel
()
{
var
h
:
CGFloat
=
nil
==
detail
?
12
:
detailLabel
.
font
.
stringSize
(
detail
!
,
constrainedToWidth
:
Double
(
width
))
.
height
let
h
:
CGFloat
=
nil
==
detail
?
12
:
detailLabel
.
font
.
stringSize
(
detail
!
,
constrainedToWidth
:
Double
(
width
))
.
height
detailLabel
.
frame
=
CGRectMake
(
0
,
divider
.
frame
.
origin
.
y
+
8
,
width
,
h
)
detailLabel
.
frame
=
CGRectMake
(
0
,
divider
.
frame
.
origin
.
y
+
8
,
width
,
h
)
}
}
...
...
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