Commit 0b014dfd by Daniel Dahan

added spin animation and cleaned up pulseView

parent cb4c9195
......@@ -20,24 +20,13 @@ import UIKit
public struct MaterialAnimation {
/**
:name: rotate
:name: spin
*/
public static func rotate(layer: CALayer, duration: CFTimeInterval, completion: (() -> Void)? = nil) {
CATransaction.begin()
CATransaction.setAnimationDuration(duration)
let transform: CGAffineTransform = CGAffineTransformRotate(layer.affineTransform(), CGFloat(M_PI))
layer.setAffineTransform(transform)
CATransaction.setCompletionBlock(completion)
CATransaction.commit()
}
/**
:name: pulse
*/
public static func pulse(layer: CALayer, duraction: CFTimeInterval, completion: (() -> Void)? = nil) {
CATransaction.begin()
CATransaction.setAnimationDuration(1.0)
CATransaction.commit()
public static func spin(layer: CALayer, duration: CFTimeInterval, rotations: Int = 1, completion: (() -> Void)? = nil) {
let a: CABasicAnimation = CABasicAnimation()
a.keyPath = "transform.rotation"
a.duration = duration
a.byValue = M_PI * 2 * Double(rotations)
layer.addAnimation(a, forKey: nil)
}
}
......@@ -27,7 +27,11 @@ public class MaterialPulseView: MaterialView {
/**
:name: pulseColor
*/
public var pulseColor: UIColor?
public var pulseColor: UIColor? {
didSet {
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5).CGColor
}
}
/**
:name: init
......@@ -43,6 +47,7 @@ public class MaterialPulseView: MaterialView {
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)
let w: CGFloat = width / 2
......@@ -52,6 +57,7 @@ public class MaterialPulseView: MaterialView {
pulseLayer.cornerRadius = CGFloat(w / 2)
CATransaction.commit()
// expand
CATransaction.begin()
CATransaction.setAnimationDuration(0.3)
pulseLayer.transform = CATransform3DMakeScale(2, 2, 2)
......@@ -65,6 +71,7 @@ public class MaterialPulseView: MaterialView {
*/
public override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
// contract
CATransaction.begin()
CATransaction.setAnimationDuration(0.3)
pulseLayer.hidden = true
......@@ -109,7 +116,6 @@ public class MaterialPulseView: MaterialView {
// pulseLayer
pulseLayer.hidden = true
pulseLayer.backgroundColor = pulseColor?.colorWithAlphaComponent(0.5).CGColor
visualLayer.addSublayer(pulseLayer)
visualLayer.insertSublayer(pulseLayer, atIndex: 1000)
}
}
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