Commit b9f7bf00 by Daniel Dahan

development: added fade to MotionAnimation

parent 00a46e33
...@@ -63,7 +63,7 @@ extension Motion { ...@@ -63,7 +63,7 @@ extension Motion {
*/ */
public static func path(bezierPath: UIBezierPath, mode: AnimationRotationMode = .auto, duration: CFTimeInterval? = nil) -> CAKeyframeAnimation { public static func path(bezierPath: UIBezierPath, mode: AnimationRotationMode = .auto, duration: CFTimeInterval? = nil) -> CAKeyframeAnimation {
let animation = CAKeyframeAnimation() let animation = CAKeyframeAnimation()
animation.keyPath = AnimationKeyPath.position.rawValue animation.keyPath = MotionAnimationKeyPath.position.rawValue
animation.path = bezierPath.cgPath animation.path = bezierPath.cgPath
animation.rotationMode = AnimationRotationModeToValue(mode: mode) animation.rotationMode = AnimationRotationModeToValue(mode: mode)
......
...@@ -72,7 +72,7 @@ public struct PulseMotion { ...@@ -72,7 +72,7 @@ public struct PulseMotion {
/// The opcaity value for the pulse animation. /// The opcaity value for the pulse animation.
public var opacity: CGFloat = 0.18 public var opacity: CGFloat = 0.18
/** /**
An initializer that takes a given view and pulse layer. An initializer that takes a given view and pulse layer.
- Parameter pulseView: An optional UIView. - Parameter pulseView: An optional UIView.
...@@ -113,7 +113,7 @@ extension PulseMotion { ...@@ -113,7 +113,7 @@ extension PulseMotion {
layers.insert(bLayer, at: 0) layers.insert(bLayer, at: 0)
layer.masksToBounds = !(.centerRadialBeyondBounds == animation || .radialBeyondBounds == animation) layer.masksToBounds = !(.centerRadialBeyondBounds == animation || .radialBeyondBounds == animation)
let w = view.bounds.width let w = view.bounds.width
let h = view.bounds.height let h = view.bounds.height
...@@ -146,24 +146,24 @@ extension PulseMotion { ...@@ -146,24 +146,24 @@ extension PulseMotion {
switch animation { switch animation {
case .centerWithBacking, .backing, .pointWithBacking, .tap: case .centerWithBacking, .backing, .pointWithBacking, .tap:
bLayer.add(Motion.background(color: color.withAlphaComponent(opacity / 2), duration: duration), forKey: nil) bLayer.motion(duration: duration, animations: .background(color: color.withAlphaComponent(opacity / 2)))
default:break default:break
} }
switch animation { switch animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking: case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.add(Motion.scale(by: 1, duration: duration), forKey: nil) pLayer.motion(duration: duration, animations: .scale(by: 1))
default:break default:break
} }
Motion.delay(time: duration) { Motion.delay(time: duration) {
bLayer.setValue(true, forKey: "animated") bLayer.setValue(true, forKey: "animated")
} }
} }
} }
extension PulseMotion { extension PulseMotion {
/// Triggers the contracting animation. /// Triggers the contracting animation.
public mutating func contract() { public mutating func contract() {
guard let bLayer = layers.popLast() else { guard let bLayer = layers.popLast() else {
return return
...@@ -182,16 +182,13 @@ extension PulseMotion { ...@@ -182,16 +182,13 @@ extension PulseMotion {
switch animation { switch animation {
case .centerWithBacking, .backing, .pointWithBacking, .tap: case .centerWithBacking, .backing, .pointWithBacking, .tap:
bLayer.add(Motion.background(color: color.withAlphaComponent(0), duration: duration), forKey: nil) bLayer.motion(duration: duration, animations: .background(color: color.withAlphaComponent(0)))
default:break default:break
} }
switch animation { switch animation {
case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking: case .center, .centerWithBacking, .centerRadialBeyondBounds, .radialBeyondBounds, .point, .pointWithBacking:
pLayer.add(Motion.animate(group: [ pLayer.motion(duration: duration, animations: .scale(by: .center == animation ? 1 : 1.325), .background(color: color.withAlphaComponent(0)))
Motion.scale(by: .center == animation ? 1 : 1.325),
Motion.background(color: color.withAlphaComponent(0))
], duration: duration), forKey: nil)
default:break default:break
} }
...@@ -200,5 +197,5 @@ extension PulseMotion { ...@@ -200,5 +197,5 @@ extension PulseMotion {
bLayer.removeFromSuperlayer() bLayer.removeFromSuperlayer()
} }
} }
} }
} }
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