Commit c81f4dfb by Daniel Dahan

experimental: updated animation and layering

parent 174bfbcd
......@@ -273,7 +273,7 @@ public class MaterialButton : UIButton {
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
let point: CGPoint = touches.first!.locationInView(self)
if nil != visualLayer.presentationLayer()?.hitTest(point) {
// set start position
CATransaction.begin()
CATransaction.setAnimationDuration(0)
......@@ -288,10 +288,9 @@ public class MaterialButton : UIButton {
CATransaction.begin()
CATransaction.setAnimationDuration(0.3)
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()
}
}
/**
:name: touchesEnded
......@@ -309,18 +308,25 @@ public class MaterialButton : UIButton {
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
//
internal func prepareView() {
// visualLayer
layer.addSublayer(visualLayer)
visualLayer.zPosition = -1
layer.addSublayer(visualLayer)
// pulseLayer
pulseLayer.hidden = true
visualLayer.addSublayer(pulseLayer)
pulseLayer.zPosition = 1000
visualLayer.addSublayer(pulseLayer)
}
//
......@@ -338,7 +344,7 @@ public class MaterialButton : UIButton {
CATransaction.setAnimationDuration(0.3)
pulseLayer.hidden = true
pulseLayer.transform = CATransform3DIdentity
visualLayer.transform = CATransform3DIdentity
layer.transform = CATransform3DIdentity
CATransaction.commit()
}
}
\ No newline at end of file
......@@ -20,6 +20,11 @@ import UIKit
public class MaterialPulseView: MaterialView {
//
// :name: touchesLayer
//
internal lazy var touchesLayer: CAShapeLayer = CAShapeLayer()
//
// :name: pulseLayer
//
internal lazy var pulseLayer: CAShapeLayer = CAShapeLayer()
......@@ -41,12 +46,21 @@ public class MaterialPulseView: MaterialView {
}
/**
:name: layoutSubviews
*/
public override func layoutSubviews() {
super.layoutSubviews()
touchesLayer.frame = bounds
touchesLayer.cornerRadius = layer.cornerRadius
}
/**
:name: touchesBegan
*/
public override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesBegan(touches, withEvent: event)
let point: CGPoint = touches.first!.locationInView(self)
if nil != visualLayer.presentationLayer()?.hitTest(point) {
// set start position
CATransaction.begin()
CATransaction.setAnimationDuration(0)
......@@ -61,10 +75,9 @@ public class MaterialPulseView: MaterialView {
CATransaction.begin()
CATransaction.setAnimationDuration(0.3)
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()
}
}
/**
:name: touchesEnded
......@@ -82,6 +95,13 @@ public class MaterialPulseView: MaterialView {
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
//
......@@ -103,10 +123,13 @@ public class MaterialPulseView: MaterialView {
borderWidth = MaterialTheme.pulseView.borderWidth
borderColor = MaterialTheme.pulseView.bordercolor
// pulseLayer
// touchesLayer
touchesLayer.zPosition = 1000
touchesLayer.masksToBounds = true
layer.addSublayer(touchesLayer)
pulseLayer.hidden = true
visualLayer.addSublayer(pulseLayer)
pulseLayer.zPosition = 1000
touchesLayer.addSublayer(pulseLayer)
}
//
......@@ -117,7 +140,7 @@ public class MaterialPulseView: MaterialView {
CATransaction.setAnimationDuration(0.3)
pulseLayer.hidden = true
pulseLayer.transform = CATransform3DIdentity
visualLayer.transform = CATransform3DIdentity
layer.transform = CATransform3DIdentity
CATransaction.commit()
}
}
......@@ -128,7 +128,7 @@ public extension MaterialTheme.navigation {
public static let lightContentStatusBar: Bool = true
// interaction
public static let userInteractionEnabled: Bool = false
public static let userInteractionEnabled: Bool = true
// image
public static let contentsRect: CGRect = MaterialTheme.view.contentsRect
......
......@@ -187,7 +187,7 @@ public class MaterialView: UIView {
*/
public var cornerRadius: MaterialRadius! {
didSet {
visualLayer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .Radius0 : cornerRadius!)
layer.cornerRadius = MaterialRadiusToValue(nil == cornerRadius ? .Radius0 : cornerRadius!)
shape = nil
}
}
......@@ -213,7 +213,7 @@ public class MaterialView: UIView {
*/
public var borderWidth: MaterialBorder! {
didSet {
visualLayer.borderWidth = MaterialBorderToValue(nil == borderWidth ? .Border0 : borderWidth!)
layer.borderWidth = MaterialBorderToValue(nil == borderWidth ? .Border0 : borderWidth!)
}
}
......@@ -222,7 +222,7 @@ public class MaterialView: UIView {
*/
public var borderColor: UIColor! {
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 {
public override func layoutSubviews() {
super.layoutSubviews()
visualLayer.frame = bounds
visualLayer.cornerRadius = layer.cornerRadius
}
//
......@@ -304,15 +305,15 @@ public class MaterialView: UIView {
borderColor = MaterialTheme.view.bordercolor
// visualLayer
layer.addSublayer(visualLayer)
visualLayer.zPosition = -1
layer.addSublayer(visualLayer)
}
//
// :name: 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