Commit c81f4dfb by Daniel Dahan

experimental: updated animation and layering

parent 174bfbcd
...@@ -273,24 +273,23 @@ public class MaterialButton : UIButton { ...@@ -273,24 +273,23 @@ public class MaterialButton : UIButton {
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event) super.touchesBegan(touches, withEvent: event)
let point: CGPoint = touches.first!.locationInView(self) let point: CGPoint = touches.first!.locationInView(self)
if nil != visualLayer.presentationLayer()?.hitTest(point) {
// set start position // set start position
CATransaction.begin() CATransaction.begin()
CATransaction.setAnimationDuration(0) CATransaction.setAnimationDuration(0)
let w: CGFloat = width / 2 let w: CGFloat = width / 2
pulseLayer.hidden = false pulseLayer.hidden = false
pulseLayer.position = point pulseLayer.position = point
pulseLayer.bounds = CGRectMake(0, 0, w, w) pulseLayer.bounds = CGRectMake(0, 0, w, w)
pulseLayer.cornerRadius = CGFloat(w / 2) pulseLayer.cornerRadius = CGFloat(w / 2)
CATransaction.commit() CATransaction.commit()
// expand // expand
CATransaction.begin() CATransaction.begin()
CATransaction.setAnimationDuration(0.3) CATransaction.setAnimationDuration(0.3)
pulseLayer.transform = CATransform3DMakeScale(2.5, 2.5, 2.5) pulseLayer.transform = CATransform3DMakeScale(2.5, 2.5, 2.5)
visualLayer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05) layer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05)
CATransaction.commit() CATransaction.commit()
}
} }
/** /**
...@@ -309,18 +308,25 @@ public class MaterialButton : UIButton { ...@@ -309,18 +308,25 @@ public class MaterialButton : UIButton {
shrink() shrink()
} }
/**
:name: actionForLayer
*/
public override func actionForLayer(layer: CALayer, forKey event: String) -> CAAction? {
return nil // returning nil enables the animations for the layer property that are normally disabled.
}
// //
// :name: prepareView // :name: prepareView
// //
internal func prepareView() { internal func prepareView() {
// visualLayer // visualLayer
layer.addSublayer(visualLayer)
visualLayer.zPosition = -1 visualLayer.zPosition = -1
layer.addSublayer(visualLayer)
// pulseLayer // pulseLayer
pulseLayer.hidden = true pulseLayer.hidden = true
visualLayer.addSublayer(pulseLayer)
pulseLayer.zPosition = 1000 pulseLayer.zPosition = 1000
visualLayer.addSublayer(pulseLayer)
} }
// //
...@@ -338,7 +344,7 @@ public class MaterialButton : UIButton { ...@@ -338,7 +344,7 @@ public class MaterialButton : UIButton {
CATransaction.setAnimationDuration(0.3) CATransaction.setAnimationDuration(0.3)
pulseLayer.hidden = true pulseLayer.hidden = true
pulseLayer.transform = CATransform3DIdentity pulseLayer.transform = CATransform3DIdentity
visualLayer.transform = CATransform3DIdentity layer.transform = CATransform3DIdentity
CATransaction.commit() CATransaction.commit()
} }
} }
\ No newline at end of file
...@@ -20,6 +20,11 @@ import UIKit ...@@ -20,6 +20,11 @@ import UIKit
public class MaterialPulseView: MaterialView { public class MaterialPulseView: MaterialView {
// //
// :name: touchesLayer
//
internal lazy var touchesLayer: CAShapeLayer = CAShapeLayer()
//
// :name: pulseLayer // :name: pulseLayer
// //
internal lazy var pulseLayer: CAShapeLayer = CAShapeLayer() internal lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
...@@ -41,29 +46,37 @@ public class MaterialPulseView: MaterialView { ...@@ -41,29 +46,37 @@ public class MaterialPulseView: MaterialView {
} }
/** /**
:name: layoutSubviews
*/
public override func layoutSubviews() {
super.layoutSubviews()
touchesLayer.frame = bounds
touchesLayer.cornerRadius = layer.cornerRadius
}
/**
:name: touchesBegan :name: touchesBegan
*/ */
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event) super.touchesBegan(touches, withEvent: event)
let point: CGPoint = touches.first!.locationInView(self) let point: CGPoint = touches.first!.locationInView(self)
if nil != visualLayer.presentationLayer()?.hitTest(point) {
// set start position // set start position
CATransaction.begin() CATransaction.begin()
CATransaction.setAnimationDuration(0) CATransaction.setAnimationDuration(0)
let w: CGFloat = width / 2 let w: CGFloat = width / 2
pulseLayer.hidden = false pulseLayer.hidden = false
pulseLayer.position = point pulseLayer.position = point
pulseLayer.bounds = CGRectMake(0, 0, w, w) pulseLayer.bounds = CGRectMake(0, 0, w, w)
pulseLayer.cornerRadius = CGFloat(w / 2) pulseLayer.cornerRadius = CGFloat(w / 2)
CATransaction.commit() CATransaction.commit()
// expand // expand
CATransaction.begin() CATransaction.begin()
CATransaction.setAnimationDuration(0.3) CATransaction.setAnimationDuration(0.3)
pulseLayer.transform = CATransform3DMakeScale(2.5, 2.5, 2.5) pulseLayer.transform = CATransform3DMakeScale(2.5, 2.5, 2.5)
visualLayer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05) layer.transform = CATransform3DMakeScale(1.05, 1.05, 1.05)
CATransaction.commit() CATransaction.commit()
}
} }
/** /**
...@@ -82,6 +95,13 @@ public class MaterialPulseView: MaterialView { ...@@ -82,6 +95,13 @@ public class MaterialPulseView: MaterialView {
shrink() shrink()
} }
/**
:name: actionForLayer
*/
public override func actionForLayer(layer: CALayer, forKey event: String) -> CAAction? {
return nil // returning nil enables the animations for the layer property that are normally disabled.
}
// //
// :name: prepareView // :name: prepareView
// //
...@@ -103,10 +123,13 @@ public class MaterialPulseView: MaterialView { ...@@ -103,10 +123,13 @@ public class MaterialPulseView: MaterialView {
borderWidth = MaterialTheme.pulseView.borderWidth borderWidth = MaterialTheme.pulseView.borderWidth
borderColor = MaterialTheme.pulseView.bordercolor borderColor = MaterialTheme.pulseView.bordercolor
// pulseLayer // touchesLayer
touchesLayer.zPosition = 1000
touchesLayer.masksToBounds = true
layer.addSublayer(touchesLayer)
pulseLayer.hidden = true pulseLayer.hidden = true
visualLayer.addSublayer(pulseLayer) touchesLayer.addSublayer(pulseLayer)
pulseLayer.zPosition = 1000
} }
// //
...@@ -117,7 +140,7 @@ public class MaterialPulseView: MaterialView { ...@@ -117,7 +140,7 @@ public class MaterialPulseView: MaterialView {
CATransaction.setAnimationDuration(0.3) CATransaction.setAnimationDuration(0.3)
pulseLayer.hidden = true pulseLayer.hidden = true
pulseLayer.transform = CATransform3DIdentity pulseLayer.transform = CATransform3DIdentity
visualLayer.transform = CATransform3DIdentity layer.transform = CATransform3DIdentity
CATransaction.commit() CATransaction.commit()
} }
} }
...@@ -128,7 +128,7 @@ public extension MaterialTheme.navigation { ...@@ -128,7 +128,7 @@ public extension MaterialTheme.navigation {
public static let lightContentStatusBar: Bool = true public static let lightContentStatusBar: Bool = true
// interaction // interaction
public static let userInteractionEnabled: Bool = false public static let userInteractionEnabled: Bool = true
// image // image
public static let contentsRect: CGRect = MaterialTheme.view.contentsRect public static let contentsRect: CGRect = MaterialTheme.view.contentsRect
......
...@@ -187,7 +187,7 @@ public class MaterialView: UIView { ...@@ -187,7 +187,7 @@ public class MaterialView: UIView {
*/ */
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
} }
} }
...@@ -213,7 +213,7 @@ public class MaterialView: UIView { ...@@ -213,7 +213,7 @@ public class MaterialView: UIView {
*/ */
public var borderWidth: MaterialBorder! { public var borderWidth: MaterialBorder! {
didSet { didSet {
visualLayer.borderWidth = MaterialBorderToValue(nil == borderWidth ? .Border0 : borderWidth!) layer.borderWidth = MaterialBorderToValue(nil == borderWidth ? .Border0 : borderWidth!)
} }
} }
...@@ -222,7 +222,7 @@ public class MaterialView: UIView { ...@@ -222,7 +222,7 @@ public class MaterialView: UIView {
*/ */
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
} }
} }
...@@ -282,6 +282,7 @@ public class MaterialView: UIView { ...@@ -282,6 +282,7 @@ public class MaterialView: UIView {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
visualLayer.frame = bounds visualLayer.frame = bounds
visualLayer.cornerRadius = layer.cornerRadius
} }
// //
...@@ -304,15 +305,15 @@ public class MaterialView: UIView { ...@@ -304,15 +305,15 @@ public class MaterialView: UIView {
borderColor = MaterialTheme.view.bordercolor borderColor = MaterialTheme.view.bordercolor
// visualLayer // visualLayer
layer.addSublayer(visualLayer)
visualLayer.zPosition = -1 visualLayer.zPosition = -1
layer.addSublayer(visualLayer)
} }
// //
// :name: prepareShape // :name: prepareShape
// //
internal func prepareShape() { internal func prepareShape() {
visualLayer.cornerRadius = .Square == shape ? 0 : width / 2 layer.cornerRadius = .Square == shape ? 0 : width / 2
} }
} }
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