Commit 159f7a6c by Daniel Dahan

added pulseFill and pulseScale booleans

parent 80a0075e
...@@ -35,6 +35,16 @@ public class MaterialButton : UIButton { ...@@ -35,6 +35,16 @@ public class MaterialButton : UIButton {
public private(set) lazy var pulseLayer: CAShapeLayer = CAShapeLayer() public private(set) lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
/** /**
:name: pulseScale
*/
public lazy var pulseScale: Bool = true
/**
:name: pulseFill
*/
public lazy var pulseFill: Bool = false
/**
:name: pulseColorOpacity :name: pulseColorOpacity
*/ */
public var pulseColorOpacity: CGFloat! { public var pulseColorOpacity: CGFloat! {
...@@ -322,10 +332,9 @@ public class MaterialButton : UIButton { ...@@ -322,10 +332,9 @@ public class MaterialButton : UIButton {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
CATransaction.begin() MaterialAnimation.animationDisabled({
CATransaction.setDisableActions(true) self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!) })
CATransaction.commit()
} }
layer.removeAnimationForKey(a.keyPath!) layer.removeAnimationForKey(a.keyPath!)
visualLayer.removeAnimationForKey(a.keyPath!) visualLayer.removeAnimationForKey(a.keyPath!)
...@@ -364,7 +373,7 @@ public class MaterialButton : UIButton { ...@@ -364,7 +373,7 @@ public class MaterialButton : UIButton {
let s: CGFloat = (width < height ? height : width) / 2 let s: CGFloat = (width < height ? height : width) / 2
let f: CGFloat = 3 let f: CGFloat = 3
let v: CGFloat = s / f let v: CGFloat = s / f
let d: CGFloat = 2 * f let d: CGFloat = pulseFill ? 5 * f : 2 * f
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled({
self.pulseLayer.hidden = false self.pulseLayer.hidden = false
self.pulseLayer.bounds = CGRectMake(0, 0, v, v) self.pulseLayer.bounds = CGRectMake(0, 0, v, v)
...@@ -373,7 +382,9 @@ public class MaterialButton : UIButton { ...@@ -373,7 +382,9 @@ public class MaterialButton : UIButton {
}) })
MaterialAnimation.animationWithDuration(0.25, animations: { MaterialAnimation.animationWithDuration(0.25, animations: {
self.pulseLayer.transform = CATransform3DMakeScale(d, d, d) self.pulseLayer.transform = CATransform3DMakeScale(d, d, d)
if self.pulseScale {
self.layer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05) self.layer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05)
}
}) })
} }
} }
...@@ -453,7 +464,9 @@ public class MaterialButton : UIButton { ...@@ -453,7 +464,9 @@ public class MaterialButton : UIButton {
MaterialAnimation.animationWithDuration(0.25, animations: { MaterialAnimation.animationWithDuration(0.25, animations: {
self.pulseLayer.hidden = true self.pulseLayer.hidden = true
self.pulseLayer.transform = CATransform3DIdentity self.pulseLayer.transform = CATransform3DIdentity
if self.pulseScale {
self.layer.transform = CATransform3DIdentity self.layer.transform = CATransform3DIdentity
}
}) })
} }
} }
\ No newline at end of file
...@@ -30,6 +30,16 @@ public class MaterialPulseView : MaterialView { ...@@ -30,6 +30,16 @@ public class MaterialPulseView : MaterialView {
public private(set) lazy var pulseLayer: CAShapeLayer = CAShapeLayer() public private(set) lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
/** /**
:name: pulseScale
*/
public lazy var pulseScale: Bool = true
/**
:name: pulseFill
*/
public lazy var pulseFill: Bool = false
/**
:name: pulseColorOpacity :name: pulseColorOpacity
*/ */
public var pulseColorOpacity: CGFloat! { public var pulseColorOpacity: CGFloat! {
...@@ -59,7 +69,7 @@ public class MaterialPulseView : MaterialView { ...@@ -59,7 +69,7 @@ public class MaterialPulseView : MaterialView {
let s: CGFloat = (width < height ? height : width) / 2 let s: CGFloat = (width < height ? height : width) / 2
let f: CGFloat = 3 let f: CGFloat = 3
let v: CGFloat = s / f let v: CGFloat = s / f
let d: CGFloat = 2 * f let d: CGFloat = pulseFill ? 5 * f : 2 * f
MaterialAnimation.animationDisabled({ MaterialAnimation.animationDisabled({
self.pulseLayer.hidden = false self.pulseLayer.hidden = false
self.pulseLayer.bounds = CGRectMake(0, 0, v, v) self.pulseLayer.bounds = CGRectMake(0, 0, v, v)
...@@ -68,7 +78,9 @@ public class MaterialPulseView : MaterialView { ...@@ -68,7 +78,9 @@ public class MaterialPulseView : MaterialView {
}) })
MaterialAnimation.animationWithDuration(0.25, animations: { MaterialAnimation.animationWithDuration(0.25, animations: {
self.pulseLayer.transform = CATransform3DMakeScale(d, d, d) self.pulseLayer.transform = CATransform3DMakeScale(d, d, d)
if self.pulseScale {
self.layer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05) self.layer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05)
}
}) })
} }
} }
...@@ -153,7 +165,9 @@ public class MaterialPulseView : MaterialView { ...@@ -153,7 +165,9 @@ public class MaterialPulseView : MaterialView {
MaterialAnimation.animationWithDuration(0.25, animations: { MaterialAnimation.animationWithDuration(0.25, animations: {
self.pulseLayer.hidden = true self.pulseLayer.hidden = true
self.pulseLayer.transform = CATransform3DIdentity self.pulseLayer.transform = CATransform3DIdentity
if self.pulseScale {
self.layer.transform = CATransform3DIdentity self.layer.transform = CATransform3DIdentity
}
}) })
} }
} }
...@@ -194,7 +194,7 @@ public extension MaterialTheme.flatButton { ...@@ -194,7 +194,7 @@ public extension MaterialTheme.flatButton {
// shape // shape
public static var masksToBounds: Bool = true public static var masksToBounds: Bool = true
public static var cornerRadius: MaterialRadius = .Radius1 public static var cornerRadius: MaterialRadius = .Radius1
public static var contentInsets: MaterialInsets = .Rectangle2 public static var contentInsets: MaterialInsets = .Rectangle3
public static var shape: MaterialShape? = nil public static var shape: MaterialShape? = nil
// border // border
......
...@@ -329,10 +329,9 @@ public class MaterialView : UIView { ...@@ -329,10 +329,9 @@ public class MaterialView : UIView {
public override func animationDidStop(anim: CAAnimation, finished flag: Bool) { public override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
if let a: CAPropertyAnimation = anim as? CAPropertyAnimation { if let a: CAPropertyAnimation = anim as? CAPropertyAnimation {
if let b: CABasicAnimation = a as? CABasicAnimation { if let b: CABasicAnimation = a as? CABasicAnimation {
CATransaction.begin() MaterialAnimation.animationDisabled({
CATransaction.setDisableActions(true) self.layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!)
layer.setValue(nil == b.toValue ? b.byValue : b.toValue, forKey: b.keyPath!) })
CATransaction.commit()
} }
layer.removeAnimationForKey(a.keyPath!) layer.removeAnimationForKey(a.keyPath!)
visualLayer.removeAnimationForKey(a.keyPath!) visualLayer.removeAnimationForKey(a.keyPath!)
......
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