Commit 469f4cfc by Daniel Dahan

development: added MotionAnimation enum type and helper methods to CALayer and UIView as extensions

parent 62b4f4ac
......@@ -248,61 +248,6 @@ extension CALayer {
}
}
/**
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
- Parameter animation: A CAAnimation instance.
*/
open func animate(animation: CAAnimation) {
animation.delegate = self
if let a = animation as? CABasicAnimation {
a.fromValue = (presentation() ?? self).value(forKeyPath: a.keyPath!)
}
if let a = animation as? CAPropertyAnimation {
add(a, forKey: a.keyPath!)
} else if let a = animation as? CAAnimationGroup {
add(a, forKey: nil)
} else if let a = animation as? CATransition {
add(a, forKey: kCATransition)
}
}
/**
A delegation method that is executed when the backing layer stops
running an animation.
- Parameter animation: The CAAnimation instance that stopped running.
- Parameter flag: A boolean that indicates if the animation stopped
because it was completed or interrupted. True if completed, false
if interrupted.
*/
open func animationDidStop(_ animation: CAAnimation, finished flag: Bool) {
guard let a = animation as? CAPropertyAnimation else {
if let a = (animation as? CAAnimationGroup)?.animations {
for x in a {
animationDidStop(x, finished: true)
}
}
return
}
guard let b = a as? CABasicAnimation else {
return
}
guard let v = b.toValue else {
return
}
guard let k = b.keyPath else {
return
}
setValue(v, forKeyPath: k)
removeAnimation(forKey: k)
}
/// Manages the layout for the shape of the view instance.
open func layoutShape() {
guard .none != shapePreset else {
......@@ -335,12 +280,9 @@ extension CALayer {
} else if nil == shadowPath {
shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath
} else {
let a = Motion.shadowPath(to: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath)
let a = Motion.shadow(path: UIBezierPath(roundedRect: bounds, cornerRadius: cornerRadius).cgPath)
a.fromValue = shadowPath
animate(animation: a)
}
}
}
@available(iOS 10, *)
extension CALayer: CAAnimationDelegate {}
......@@ -268,15 +268,6 @@ extension UIView {
}
}
/**
A method that accepts CAAnimation objects and executes them on the
view's backing layer.
- Parameter animation: A CAAnimation instance.
*/
open func animate(animation: CAAnimation) {
layer.animate(animation: animation)
}
/// Manages the layout for the shape of the view instance.
open func layoutShape() {
layer.layoutShape()
......
......@@ -146,7 +146,7 @@ extension PulseMotion {
switch animation {
case .centerWithBacking, .backing, .pointWithBacking, .tap:
bLayer.add(Motion.backgroundColor(color: color.withAlphaComponent(opacity / 2), duration: duration), forKey: nil)
bLayer.add(Motion.background(color: color.withAlphaComponent(opacity / 2), duration: duration), forKey: nil)
default:break
}
......@@ -182,7 +182,7 @@ extension PulseMotion {
switch animation {
case .centerWithBacking, .backing, .pointWithBacking, .tap:
bLayer.add(Motion.backgroundColor(color: color.withAlphaComponent(0), duration: duration), forKey: nil)
bLayer.add(Motion.background(color: color.withAlphaComponent(0), duration: duration), forKey: nil)
default:break
}
......@@ -190,7 +190,7 @@ extension PulseMotion {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.add(Motion.animate(group: [
Motion.scale(by: .center == animation ? 1 : 1.325),
Motion.backgroundColor(color: color.withAlphaComponent(0))
Motion.background(color: color.withAlphaComponent(0))
], duration: duration), forKey: nil)
default:break
}
......
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