Commit 159f7a6c by Daniel Dahan

added pulseFill and pulseScale booleans

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