Commit 7b65791f by Colin Morelli

Add pulseCenter property to MaterialButton

parent 6251dcdc
...@@ -55,12 +55,15 @@ public class MaterialButton : UIButton { ...@@ -55,12 +55,15 @@ public class MaterialButton : UIButton {
/// Sets whether the scaling animation should be used. /// Sets whether the scaling animation should be used.
@IBInspectable public lazy var pulseScale: Bool = true @IBInspectable public lazy var pulseScale: Bool = true
/// The opcaity 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.25
/// 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
...@@ -436,13 +439,14 @@ public class MaterialButton : UIButton { ...@@ -436,13 +439,14 @@ 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) let duration: NSTimeInterval = MaterialAnimation.pulseDuration(width)
let point: CGPoint = pulseCenter ? CGPointMake(CGFloat(width / 2), CGFloat(height / 2)) : layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer)
if pulseFocus { if pulseFocus {
pulseLayer = CAShapeLayer() pulseLayer = CAShapeLayer()
} }
if let v: UIColor = pulseColor { if let v: UIColor = pulseColor {
MaterialAnimation.pulseAnimation(layer, visualLayer: visualLayer, color: v.colorWithAlphaComponent(pulseOpacity), point: layer.convertPoint(touches.first!.locationInView(self), fromLayer: layer), width: width, height: height, duration: duration, pulseLayer: pulseLayer) MaterialAnimation.pulseAnimation(layer, visualLayer: visualLayer, color: v.colorWithAlphaComponent(pulseOpacity), point: point, width: width, height: height, duration: duration, pulseLayer: pulseLayer)
} }
if pulseScale { if pulseScale {
...@@ -519,4 +523,4 @@ public class MaterialButton : UIButton { ...@@ -519,4 +523,4 @@ public class MaterialButton : UIButton {
} }
} }
} }
} }
\ No newline at end of file
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