Commit a2cf6137 by Daniel Dahan

experimental: updated button animations

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