Commit a2cf6137 by Daniel Dahan

experimental: updated button animations

parent c81f4dfb
...@@ -25,14 +25,23 @@ public class MaterialButton : UIButton { ...@@ -25,14 +25,23 @@ public class MaterialButton : UIButton {
public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer() public private(set) lazy var visualLayer: CAShapeLayer = CAShapeLayer()
// //
// :name: pulseLayer // :name: touchesLayer
// //
internal lazy var pulseLayer: CAShapeLayer = CAShapeLayer() internal lazy var touchesLayer: CAShapeLayer = CAShapeLayer()
// //
// :name: pulseColorOpacity // :name: pulseLayer
// //
internal var pulseColorOpacity: CGFloat! internal lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
/**
:name: pulseColorOpacity
*/
public var pulseColorOpacity: CGFloat! {
didSet {
pulseColorOpacity = nil == pulseColorOpacity ? 0.5 : pulseColorOpacity!
}
}
/** /**
:name: pulseColor :name: pulseColor
...@@ -161,7 +170,7 @@ public class MaterialButton : UIButton { ...@@ -161,7 +170,7 @@ public class MaterialButton : UIButton {
*/ */
public var cornerRadius: MaterialRadius! { public var cornerRadius: MaterialRadius! {
didSet { didSet {
visualLayer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .Radius0 : cornerRadius!) layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .Radius0 : cornerRadius!)
shape = nil shape = nil
} }
} }
...@@ -187,7 +196,7 @@ public class MaterialButton : UIButton { ...@@ -187,7 +196,7 @@ public class MaterialButton : UIButton {
*/ */
public var borderWidth: MaterialBorder! { public var borderWidth: MaterialBorder! {
didSet { didSet {
visualLayer.borderWidth = MaterialBorderToValue(nil == borderWidth ? .Border0 : borderWidth!) layer.borderWidth = MaterialBorderToValue(nil == borderWidth ? .Border0 : borderWidth!)
} }
} }
...@@ -196,7 +205,7 @@ public class MaterialButton : UIButton { ...@@ -196,7 +205,7 @@ public class MaterialButton : UIButton {
*/ */
public var borderColor: UIColor! { public var borderColor: UIColor! {
didSet { didSet {
visualLayer.borderColor = nil == borderColor ? MaterialColor.clear.CGColor : borderColor!.CGColor layer.borderColor = nil == borderColor ? MaterialColor.clear.CGColor : borderColor!.CGColor
} }
} }
...@@ -265,6 +274,10 @@ public class MaterialButton : UIButton { ...@@ -265,6 +274,10 @@ public class MaterialButton : UIButton {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
visualLayer.frame = bounds visualLayer.frame = bounds
visualLayer.cornerRadius = layer.cornerRadius
touchesLayer.frame = bounds
touchesLayer.cornerRadius = layer.cornerRadius
} }
/** /**
...@@ -323,17 +336,21 @@ public class MaterialButton : UIButton { ...@@ -323,17 +336,21 @@ public class MaterialButton : UIButton {
visualLayer.zPosition = -1 visualLayer.zPosition = -1
layer.addSublayer(visualLayer) layer.addSublayer(visualLayer)
// touchesLayer
touchesLayer.zPosition = 1000
touchesLayer.masksToBounds = true
layer.addSublayer(touchesLayer)
// pulseLayer // pulseLayer
pulseLayer.hidden = true pulseLayer.hidden = true
pulseLayer.zPosition = 1000 touchesLayer.addSublayer(pulseLayer)
visualLayer.addSublayer(pulseLayer)
} }
// //
// :name: prepareShape // :name: prepareShape
// //
internal func prepareShape() { internal func prepareShape() {
visualLayer.cornerRadius = .Square == shape ? 0 : width / 2 layer.cornerRadius = .Square == shape ? 0 : width / 2
} }
// //
......
...@@ -30,11 +30,20 @@ public class MaterialPulseView: MaterialView { ...@@ -30,11 +30,20 @@ public class MaterialPulseView: MaterialView {
internal lazy var pulseLayer: CAShapeLayer = CAShapeLayer() internal lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
/** /**
:name: pulseColorOpacity
*/
public var pulseColorOpacity: CGFloat! {
didSet {
pulseColorOpacity = nil == pulseColorOpacity ? 0.5 : pulseColorOpacity!
}
}
/**
:name: pulseColor :name: pulseColor
*/ */
public var pulseColor: UIColor? { public var pulseColor: UIColor? {
didSet { didSet {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(MaterialTheme.pulseView.pulseColorOpacity).CGColor pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(pulseColorOpacity!).CGColor
} }
} }
...@@ -109,6 +118,7 @@ public class MaterialPulseView: MaterialView { ...@@ -109,6 +118,7 @@ public class MaterialPulseView: MaterialView {
super.prepareView() super.prepareView()
userInteractionEnabled = MaterialTheme.pulseView.userInteractionEnabled userInteractionEnabled = MaterialTheme.pulseView.userInteractionEnabled
backgroundColor = MaterialTheme.pulseView.backgroudColor backgroundColor = MaterialTheme.pulseView.backgroudColor
pulseColorOpacity = MaterialTheme.pulseView.pulseColorOpacity
pulseColor = MaterialTheme.pulseView.pulseColor pulseColor = MaterialTheme.pulseView.pulseColor
contentsRect = MaterialTheme.pulseView.contentsRect contentsRect = MaterialTheme.pulseView.contentsRect
...@@ -128,6 +138,7 @@ public class MaterialPulseView: MaterialView { ...@@ -128,6 +138,7 @@ public class MaterialPulseView: MaterialView {
touchesLayer.masksToBounds = true touchesLayer.masksToBounds = true
layer.addSublayer(touchesLayer) layer.addSublayer(touchesLayer)
// pulseLayer
pulseLayer.hidden = true pulseLayer.hidden = true
touchesLayer.addSublayer(pulseLayer) touchesLayer.addSublayer(pulseLayer)
} }
......
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