Commit 83482643 by Daniel Dahan

added pulseAnimation enum

parent cbedb1d7
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
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 */; };
...@@ -22,7 +20,6 @@ ...@@ -22,7 +20,6 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
9658F1FA1CD6AA4900B902C1 /* 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 */
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>"; };
...@@ -44,7 +40,6 @@ ...@@ -44,7 +40,6 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
9658F1F91CD6AA4900B902C1 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -54,7 +49,6 @@ ...@@ -54,7 +49,6 @@
965E8E651C14A4950035A270 = { 965E8E651C14A4950035A270 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9658F1F81CD6AA4900B902C1 /* Material.framework */,
965E8E701C14A4950035A270 /* MaterialButton */, 965E8E701C14A4950035A270 /* MaterialButton */,
965E8E6F1C14A4950035A270 /* Products */, 965E8E6F1C14A4950035A270 /* Products */,
); );
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
9658F2111CD6CDD700B902C1 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F2101CD6CDD700B902C1 /* Material.framework */; };
9658F2121CD6CDD700B902C1 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9658F2101CD6CDD700B902C1 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
96DB1C5F1C14AA2800825BE6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DB1C5E1C14AA2800825BE6 /* AppDelegate.swift */; }; 96DB1C5F1C14AA2800825BE6 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DB1C5E1C14AA2800825BE6 /* AppDelegate.swift */; };
96DB1C611C14AA2800825BE6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DB1C601C14AA2800825BE6 /* ViewController.swift */; }; 96DB1C611C14AA2800825BE6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96DB1C601C14AA2800825BE6 /* ViewController.swift */; };
96DB1C661C14AA2800825BE6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96DB1C651C14AA2800825BE6 /* Assets.xcassets */; }; 96DB1C661C14AA2800825BE6 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96DB1C651C14AA2800825BE6 /* Assets.xcassets */; };
...@@ -20,6 +22,7 @@ ...@@ -20,6 +22,7 @@
dstPath = ""; dstPath = "";
dstSubfolderSpec = 10; dstSubfolderSpec = 10;
files = ( files = (
9658F2121CD6CDD700B902C1 /* 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 */
9658F2101CD6CDD700B902C1 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/danieldahan/Library/Developer/Xcode/DerivedData/Material-bshwisidfobstlbomegqyybbrygh/Build/Products/Debug-iphonesimulator/Material.framework"; sourceTree = "<absolute>"; };
96DB1C5B1C14AA2800825BE6 /* MaterialPulseView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MaterialPulseView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 96DB1C5B1C14AA2800825BE6 /* MaterialPulseView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MaterialPulseView.app; sourceTree = BUILT_PRODUCTS_DIR; };
96DB1C5E1C14AA2800825BE6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; }; 96DB1C5E1C14AA2800825BE6 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
96DB1C601C14AA2800825BE6 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; }; 96DB1C601C14AA2800825BE6 /* 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 = (
9658F2111CD6CDD700B902C1 /* Material.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -49,6 +54,7 @@ ...@@ -49,6 +54,7 @@
96DB1C521C14AA2800825BE6 = { 96DB1C521C14AA2800825BE6 = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
9658F2101CD6CDD700B902C1 /* Material.framework */,
96DB1C5D1C14AA2800825BE6 /* MaterialPulseView */, 96DB1C5D1C14AA2800825BE6 /* MaterialPulseView */,
96DB1C5C1C14AA2800825BE6 /* Products */, 96DB1C5C1C14AA2800825BE6 /* Products */,
); );
......
...@@ -41,7 +41,7 @@ class ViewController: UIViewController { ...@@ -41,7 +41,7 @@ class ViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
prepareView() prepareView()
prepareGeneralMaterialPulseViewExample() prepareMaterialPulseView()
} }
/// General preparation statements. /// General preparation statements.
...@@ -50,16 +50,16 @@ class ViewController: UIViewController { ...@@ -50,16 +50,16 @@ class ViewController: UIViewController {
} }
/// Prepares the MaterialPulseView example. /// Prepares the MaterialPulseView example.
private func prepareGeneralMaterialPulseViewExample() { private func prepareMaterialPulseView() {
let diameter: CGFloat = 150 let diameter: CGFloat = 150
let point: CGFloat = (MaterialDevice.width - diameter) / 2 let point: CGFloat = (MaterialDevice.width - diameter) / 2
let pulseView: MaterialPulseView = MaterialPulseView(frame: CGRectMake(point, point, diameter, diameter)) let pulseView: MaterialPulseView = MaterialPulseView(frame: CGRectMake(point, point, diameter, diameter))
pulseView.image = UIImage(named: "Graph") // pulseView.image = UIImage(named: "Graph")
pulseView.shape = .Square pulseView.shape = .Square
pulseView.depth = .Depth1 pulseView.depth = .Depth1
pulseView.cornerRadiusPreset = .Radius3 pulseView.cornerRadiusPreset = .Radius3
// pulseView.pulseFocus = true // Optional focus animation. // pulseView.pulseAnimation = .CenterWithBacking // Set a different type of pulse animation.
// Add pulseView to UIViewController. // Add pulseView to UIViewController.
view.addSubview(pulseView) view.addSubview(pulseView)
......
...@@ -55,6 +55,9 @@ public class MaterialButton : UIButton { ...@@ -55,6 +55,9 @@ public class MaterialButton : UIButton {
/// The color of the pulse effect. /// The color of the pulse effect.
@IBInspectable public var pulseColor: UIColor? @IBInspectable public var pulseColor: UIColor?
/// The type of PulseAnimation.
public var pulseAnimation: PulseAnimation = .AtPointWithBacking
/** /**
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
...@@ -404,11 +407,11 @@ public class MaterialButton : UIButton { ...@@ -404,11 +407,11 @@ 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!
if let color: UIColor = pulseColor { if let color: UIColor = pulseColor {
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers) MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
MaterialAnimation.delay(0.35) { [weak self] in MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialButton = self { if let s: MaterialButton = self {
MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers) MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
} }
} }
} }
...@@ -421,7 +424,7 @@ public class MaterialButton : UIButton { ...@@ -421,7 +424,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)
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, pulseLayers: &pulseLayers) MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -432,7 +435,7 @@ public class MaterialButton : UIButton { ...@@ -432,7 +435,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.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers) MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -443,7 +446,7 @@ public class MaterialButton : UIButton { ...@@ -443,7 +446,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.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers) MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
......
...@@ -55,6 +55,9 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -55,6 +55,9 @@ 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?
/// The type of PulseAnimation.
public var pulseAnimation: PulseAnimation = .AtPointWithBacking
/** /**
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
...@@ -509,11 +512,11 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -509,11 +512,11 @@ 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!
if let color: UIColor = pulseColor { if let color: UIColor = pulseColor {
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers) MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
MaterialAnimation.delay(0.35) { [weak self] in MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialCollectionViewCell = self { if let s: MaterialCollectionViewCell = self {
MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers) MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
} }
} }
} }
...@@ -526,7 +529,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -526,7 +529,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)
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, pulseLayers: &pulseLayers) MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -537,7 +540,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -537,7 +540,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.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers) MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -548,7 +551,7 @@ public class MaterialCollectionViewCell : UICollectionViewCell { ...@@ -548,7 +551,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.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers) MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
......
...@@ -30,6 +30,15 @@ ...@@ -30,6 +30,15 @@
import UIKit import UIKit
public enum PulseAnimation {
case None
case Center
case CenterWithBacking
case Backing
case AtPoint
case AtPointWithBacking
}
internal extension MaterialAnimation { internal extension MaterialAnimation {
/** /**
Triggers the expanding animation. Triggers the expanding animation.
...@@ -42,29 +51,44 @@ internal extension MaterialAnimation { ...@@ -42,29 +51,44 @@ internal extension MaterialAnimation {
- Parameter duration: Animation duration. - Parameter duration: Animation duration.
- Parameter pulseLayers: An Array of CAShapeLayers used in the animation. - Parameter pulseLayers: An Array of CAShapeLayers used in the animation.
*/ */
internal static func pulseExpandAnimation(layer: CALayer, visualLayer: CALayer, pulseColor: UIColor?, pulseOpacity: CGFloat, point: CGPoint, width: CGFloat, height: CGFloat, inout pulseLayers: Array<CAShapeLayer>) { internal static func pulseExpandAnimation(layer: CALayer, visualLayer: CALayer, pulseColor: UIColor?, pulseOpacity: CGFloat, point: CGPoint, width: CGFloat, height: CGFloat, inout pulseLayers: Array<CAShapeLayer>, pulseAnimation: PulseAnimation) {
if let color: UIColor = pulseColor { if .None != pulseAnimation {
if let n: CGFloat = width < height ? height : width { if let color: UIColor = pulseColor {
if let pOpacity: CGFloat = pulseOpacity { if let n: CGFloat = width < height ? height : width {
let bLayer: CAShapeLayer = CAShapeLayer() if let pOpacity: CGFloat = pulseOpacity {
let pLayer: CAShapeLayer = CAShapeLayer() let bLayer: CAShapeLayer = CAShapeLayer()
bLayer.addSublayer(pLayer) let pLayer: CAShapeLayer = CAShapeLayer()
pulseLayers.insert(bLayer, atIndex: 0) bLayer.addSublayer(pLayer)
visualLayer.addSublayer(bLayer) pulseLayers.insert(bLayer, atIndex: 0)
MaterialAnimation.animationDisabled({ visualLayer.addSublayer(bLayer)
bLayer.frame = visualLayer.bounds MaterialAnimation.animationDisabled({
pLayer.bounds = CGRectMake(0, 0, n, n) bLayer.frame = visualLayer.bounds
pLayer.position = point pLayer.bounds = CGRectMake(0, 0, n, n)
pLayer.cornerRadius = n / 2 switch pulseAnimation {
pLayer.backgroundColor = color.colorWithAlphaComponent(pOpacity).CGColor case .Center, .CenterWithBacking:
pLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(0, 0)) pLayer.position = CGPointMake(width / 2, height / 2)
}) default:
bLayer.setValue(false, forKey: "animated") pLayer.position = point
bLayer.addAnimation(MaterialAnimation.backgroundColor(color.colorWithAlphaComponent(pOpacity / 2), duration: 0.35), forKey: nil) }
pLayer.addAnimation(MaterialAnimation.scale(1, duration: 0.35), forKey: nil) pLayer.cornerRadius = n / 2
MaterialAnimation.delay(0.35, completion: { pLayer.backgroundColor = color.colorWithAlphaComponent(pOpacity).CGColor
bLayer.setValue(true, forKey: "animated") pLayer.transform = CATransform3DMakeAffineTransform(CGAffineTransformMakeScale(0, 0))
}) })
bLayer.setValue(false, forKey: "animated")
switch pulseAnimation {
case .CenterWithBacking, .Backing, .AtPointWithBacking:
bLayer.addAnimation(MaterialAnimation.backgroundColor(color.colorWithAlphaComponent(pOpacity / 2), duration: 0.35), forKey: nil)
default:break
}
switch pulseAnimation {
case .Center, .CenterWithBacking, .AtPoint, .AtPointWithBacking:
pLayer.addAnimation(MaterialAnimation.scale(1, duration: 0.35), forKey: nil)
default:break
}
MaterialAnimation.delay(0.35, completion: {
bLayer.setValue(true, forKey: "animated")
})
}
} }
} }
} }
...@@ -76,18 +100,25 @@ internal extension MaterialAnimation { ...@@ -76,18 +100,25 @@ internal extension MaterialAnimation {
- Parameter pulseColor: The UIColor for the pulse. - Parameter pulseColor: The UIColor for the pulse.
- Parameter pulseLayers: An Array of CAShapeLayers used in the animation. - Parameter pulseLayers: An Array of CAShapeLayers used in the animation.
*/ */
internal static func pulseContractAnimation(layer: CALayer, pulseColor: UIColor?, inout pulseLayers: Array<CAShapeLayer>) { internal static func pulseContractAnimation(layer: CALayer, pulseColor: UIColor?, inout pulseLayers: Array<CAShapeLayer>, pulseAnimation: PulseAnimation) {
if let color: UIColor = pulseColor { if let color: UIColor = pulseColor {
if let bLayer: CAShapeLayer = pulseLayers.popLast() { if let bLayer: CAShapeLayer = pulseLayers.popLast() {
let animated: Bool? = bLayer.valueForKey("animated") as? Bool let animated: Bool? = bLayer.valueForKey("animated") as? Bool
MaterialAnimation.delay(true == animated ? 0 : 0.15) { MaterialAnimation.delay(true == animated ? 0 : 0.15) {
if let pLayer: CAShapeLayer = bLayer.sublayers?.first as? CAShapeLayer { if let pLayer: CAShapeLayer = bLayer.sublayers?.first as? CAShapeLayer {
bLayer.addAnimation(MaterialAnimation.backgroundColor(color.colorWithAlphaComponent(0), duration: 0.35), forKey: nil) switch pulseAnimation {
pLayer.addAnimation(MaterialAnimation.animationGroup([ case .CenterWithBacking, .Backing, .AtPointWithBacking:
MaterialAnimation.scale(1.35), bLayer.addAnimation(MaterialAnimation.backgroundColor(color.colorWithAlphaComponent(0), duration: 0.35), forKey: nil)
MaterialAnimation.backgroundColor(color.colorWithAlphaComponent(0)) default:break
}
switch pulseAnimation {
case .Center, .CenterWithBacking, .AtPoint, .AtPointWithBacking:
pLayer.addAnimation(MaterialAnimation.animationGroup([
MaterialAnimation.scale(1.35),
MaterialAnimation.backgroundColor(color.colorWithAlphaComponent(0))
], duration: 0.35), forKey: nil) ], duration: 0.35), forKey: nil)
default:break
}
MaterialAnimation.delay(0.35) { MaterialAnimation.delay(0.35) {
pLayer.removeFromSuperlayer() pLayer.removeFromSuperlayer()
bLayer.removeFromSuperlayer() bLayer.removeFromSuperlayer()
......
...@@ -43,6 +43,9 @@ public class MaterialPulseView : MaterialView { ...@@ -43,6 +43,9 @@ 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?
/// The type of PulseAnimation.
public var pulseAnimation: PulseAnimation = .AtPointWithBacking
/** /**
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
...@@ -51,11 +54,11 @@ public class MaterialPulseView : MaterialView { ...@@ -51,11 +54,11 @@ 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!
if let color: UIColor = pulseColor { if let color: UIColor = pulseColor {
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers) MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
MaterialAnimation.delay(0.35) { [weak self] in MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialPulseView = self { if let s: MaterialPulseView = self {
MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers) MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
} }
} }
} }
...@@ -68,7 +71,7 @@ public class MaterialPulseView : MaterialView { ...@@ -68,7 +71,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)
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, pulseLayers: &pulseLayers) MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -79,7 +82,7 @@ public class MaterialPulseView : MaterialView { ...@@ -79,7 +82,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.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers) MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -90,7 +93,7 @@ public class MaterialPulseView : MaterialView { ...@@ -90,7 +93,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.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers) MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
......
...@@ -54,6 +54,9 @@ public class MaterialTableViewCell : UITableViewCell { ...@@ -54,6 +54,9 @@ 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?
/// The type of PulseAnimation.
public var pulseAnimation: PulseAnimation = .AtPointWithBacking
/** /**
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
...@@ -359,11 +362,11 @@ public class MaterialTableViewCell : UITableViewCell { ...@@ -359,11 +362,11 @@ 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!
if let color: UIColor = pulseColor { if let color: UIColor = pulseColor {
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers) MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: p, width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
MaterialAnimation.delay(0.35) { [weak self] in MaterialAnimation.delay(0.35) { [weak self] in
if let s: MaterialTableViewCell = self { if let s: MaterialTableViewCell = self {
MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers) MaterialAnimation.pulseContractAnimation(s.layer, pulseColor: s.pulseColor, pulseLayers: &s.pulseLayers, pulseAnimation: s.pulseAnimation)
} }
} }
} }
...@@ -376,7 +379,7 @@ public class MaterialTableViewCell : UITableViewCell { ...@@ -376,7 +379,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)
MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, pulseLayers: &pulseLayers) MaterialAnimation.pulseExpandAnimation(layer, visualLayer: visualLayer, pulseColor: pulseColor, pulseOpacity: pulseOpacity, point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -387,7 +390,7 @@ public class MaterialTableViewCell : UITableViewCell { ...@@ -387,7 +390,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.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers) MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
...@@ -398,7 +401,7 @@ public class MaterialTableViewCell : UITableViewCell { ...@@ -398,7 +401,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.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers) MaterialAnimation.pulseContractAnimation(layer, pulseColor: pulseColor, pulseLayers: &pulseLayers, pulseAnimation: pulseAnimation)
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment