Commit b048661a by Daniel Dahan

completed refactor

parent 156f4984
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
import UIKit import UIKit
public class AddFabButton : FabButton { public class AddFabButton : FabButton {
private lazy var verticalLine: UIView = UIView() private var verticalLine: UIView!
private lazy var horizontalLine: UIView = UIView() private var horizontalLine: UIView!
// //
// :name: prepareButton // :name: prepareButton
......
...@@ -31,35 +31,17 @@ public class FabButton : MaterialButton { ...@@ -31,35 +31,17 @@ public class FabButton : MaterialButton {
super.prepareButton() super.prepareButton()
color = .redColor() color = .redColor()
pulseColor = .whiteColor() pulseColor = .whiteColor()
}
//
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = bounds.width / 2 backgroundColorView.layer.cornerRadius = bounds.width / 2
} }
// //
// :name: pulseTouches // :name: pulseTouches
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseTouches(touches: Set<NSObject>) {
super.pulseTouches(touches) super.pulseTouches(touches)
let touch = touches.first as! UITouch UIView.animateWithDuration(0.3, animations: {
let touchLocation = touch.locationInView(self) self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
pulseView = UIView() self.transform = CGAffineTransformMakeScale(1.1, 1.1)
pulseView!.frame = CGRectMake(0, 0, bounds.width, bounds.height) })
pulseView!.layer.cornerRadius = bounds.width / 2
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
UIView.animateWithDuration(0.3,
animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
self.transform = CGAffineTransformMakeScale(1.1, 1.1)
},
completion: nil
)
} }
} }
...@@ -30,13 +30,6 @@ public class FlatButton : MaterialButton { ...@@ -30,13 +30,6 @@ public class FlatButton : MaterialButton {
internal override func prepareButton() { internal override func prepareButton() {
super.prepareButton() super.prepareButton()
pulseColor = .whiteColor() pulseColor = .whiteColor()
}
//
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = 3 backgroundColorView.layer.cornerRadius = 3
} }
...@@ -45,15 +38,7 @@ public class FlatButton : MaterialButton { ...@@ -45,15 +38,7 @@ public class FlatButton : MaterialButton {
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseTouches(touches: Set<NSObject>) {
super.pulseTouches(touches) super.pulseTouches(touches)
let touch = touches.first as! UITouch textColor = titleLabel?.textColor
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height)
pulseView!.layer.cornerRadius = bounds.height / 2.0
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
textColor = self.titleLabel?.textColor
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1) self.transform = CGAffineTransformMakeScale(1.05, 1.1)
......
...@@ -93,20 +93,31 @@ public class MaterialButton : UIButton { ...@@ -93,20 +93,31 @@ public class MaterialButton : UIButton {
*/ */
final public override func drawRect(rect: CGRect) { final public override func drawRect(rect: CGRect) {
prepareContext(rect) prepareContext(rect)
prepareButton()
prepareShadow() prepareShadow()
prepareButton()
prepareBackgroundColorView() prepareBackgroundColorView()
} }
// //
// :name: prepareButton // :name: prepareButton
// //
internal func prepareButton() {} internal func prepareButton() {
backgroundColorView.frame = bounds
}
// //
// :name: pulseTouches // :name: pulseTouches
// //
internal func pulseTouches(touches: Set<NSObject>) {} internal func pulseTouches(touches: Set<NSObject>) {
let touch = touches.first as! UITouch
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, bounds.width, bounds.height)
pulseView!.layer.cornerRadius = bounds.width / 2
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
}
// //
// :name: prepareBackgroundColorView // :name: prepareBackgroundColorView
...@@ -114,7 +125,6 @@ public class MaterialButton : UIButton { ...@@ -114,7 +125,6 @@ public class MaterialButton : UIButton {
// We need this view so we can use the masksToBounds // We need this view so we can use the masksToBounds
// so the pulse doesn't animate off the button // so the pulse doesn't animate off the button
internal func prepareBackgroundColorView() { internal func prepareBackgroundColorView() {
backgroundColorView.frame = bounds
backgroundColorView.backgroundColor = color backgroundColorView.backgroundColor = color
backgroundColorView.layer.masksToBounds = true backgroundColorView.layer.masksToBounds = true
backgroundColorView.userInteractionEnabled = false backgroundColorView.userInteractionEnabled = false
......
...@@ -31,13 +31,6 @@ public class RaisedButton : MaterialButton { ...@@ -31,13 +31,6 @@ public class RaisedButton : MaterialButton {
super.prepareButton() super.prepareButton()
color = .redColor() color = .redColor()
pulseColor = .whiteColor() pulseColor = .whiteColor()
}
//
// :name: prepareBackgroundColorView
//
internal override func prepareBackgroundColorView() {
super.prepareBackgroundColorView()
backgroundColorView.layer.cornerRadius = 3 backgroundColorView.layer.cornerRadius = 3
} }
...@@ -46,15 +39,7 @@ public class RaisedButton : MaterialButton { ...@@ -46,15 +39,7 @@ public class RaisedButton : MaterialButton {
// //
internal override func pulseTouches(touches: Set<NSObject>) { internal override func pulseTouches(touches: Set<NSObject>) {
super.pulseTouches(touches) super.pulseTouches(touches)
let touch = touches.first as! UITouch textColor = titleLabel?.textColor
let touchLocation = touch.locationInView(self)
pulseView = UIView()
pulseView!.frame = CGRectMake(0, 0, self.bounds.size.height, self.bounds.size.height)
pulseView!.layer.cornerRadius = bounds.height / 2.0
pulseView!.center = touchLocation
pulseView!.backgroundColor = pulseColor!.colorWithAlphaComponent(0.5)
backgroundColorView.addSubview(pulseView!)
textColor = self.titleLabel?.textColor
UIView.animateWithDuration(0.3, animations: { UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(10, 10) self.pulseView!.transform = CGAffineTransformMakeScale(10, 10)
self.transform = CGAffineTransformMakeScale(1.05, 1.1) self.transform = CGAffineTransformMakeScale(1.05, 1.1)
......
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