Commit af4d74d4 by Daniel Dahan

updates to MotionCoreAnimationViewContext

parent c10fe806
...@@ -118,7 +118,7 @@ internal class MotionCoreAnimationViewContext: MotionAnimatorViewContext { ...@@ -118,7 +118,7 @@ internal class MotionCoreAnimationViewContext: MotionAnimatorViewContext {
for (layer, key, anim) in animations { for (layer, key, anim) in animations {
anim.speed = 0 anim.speed = 0
anim.timeOffset = CFTimeInterval(timeOffset.clamp(0, CGFloat(anim.duration) - 0.001)) anim.timeOffset = CFTimeInterval(timeOffset.clamp(0, CGFloat(anim.duration - 0.001)))
layer.removeAnimation(forKey: key) layer.removeAnimation(forKey: key)
layer.add(anim, forKey: key) layer.add(anim, forKey: key)
} }
...@@ -360,8 +360,6 @@ fileprivate extension MotionCoreAnimationViewContext { ...@@ -360,8 +360,6 @@ fileprivate extension MotionCoreAnimationViewContext {
addAnimation(anim, for: overlayKey, to: getOverlayLayer()) addAnimation(anim, for: overlayKey, to: getOverlayLayer())
} else { } else {
snapshot.layer.add(anim, forKey: key)
switch key { switch key {
case "cornerRadius", "contentsRect", "contentsScale": case "cornerRadius", "contentsRect", "contentsScale":
addAnimation(anim, for: key, to: snapshot.layer) addAnimation(anim, for: key, to: snapshot.layer)
...@@ -375,21 +373,18 @@ fileprivate extension MotionCoreAnimationViewContext { ...@@ -375,21 +373,18 @@ fileprivate extension MotionCoreAnimationViewContext {
} }
case "bounds.size": case "bounds.size":
guard let fs = (fromValue as? NSValue)?.cgSizeValue else { guard let fromSize = (fromValue as? NSValue)?.cgSizeValue, let toSize = (toValue as? NSValue)?.cgSizeValue else {
return 0 addAnimation(anim, for: key, to: snapshot.layer)
} break
guard let ts = (toValue as? NSValue)?.cgSizeValue else {
return 0
} }
setSize(view: snapshot, newSize: fs) setSize(view: snapshot, newSize: fromSize)
uiViewBasedAnimate(duration: anim.duration, delay: beginTime - currentTime) { [weak self] in uiViewBasedAnimate(duration: anim.duration, delay: beginTime - currentTime) { [weak self] in
guard let `self` = self else { guard let `self` = self else {
return return
} }
self.setSize(view: self.snapshot, newSize: ts) self.setSize(view: self.snapshot, newSize: toSize)
} }
default: default:
......
...@@ -83,7 +83,7 @@ internal class MotionViewPropertyViewContext: MotionAnimatorViewContext { ...@@ -83,7 +83,7 @@ internal class MotionViewPropertyViewContext: MotionAnimatorViewContext {
} }
let appearedEffect = visualEffectView.effect let appearedEffect = visualEffectView.effect
let disappearedEffect = targetState.opacity == 0 ? nil : visualEffectView.effect let disappearedEffect = 0 == targetState.opacity ? nil : visualEffectView.effect
startEffect = isAppearing ? disappearedEffect : appearedEffect startEffect = isAppearing ? disappearedEffect : appearedEffect
endEffect = isAppearing ? appearedEffect : disappearedEffect endEffect = isAppearing ? appearedEffect : disappearedEffect
......
...@@ -29,6 +29,7 @@ import UIKit ...@@ -29,6 +29,7 @@ import UIKit
extension CALayer: CAAnimationDelegate {} extension CALayer: CAAnimationDelegate {}
internal extension CALayer { internal extension CALayer {
/// Swizzle the `add(_:forKey:) selector.
internal static var motionAddedAnimations: [(CALayer, String, CAAnimation)]? = { internal static var motionAddedAnimations: [(CALayer, String, CAAnimation)]? = {
let swizzling: (AnyClass, Selector, Selector) -> Void = { forClass, originalSelector, swizzledSelector in let swizzling: (AnyClass, Selector, Selector) -> Void = { forClass, originalSelector, swizzledSelector in
if let originalMethod = class_getInstanceMethod(forClass, originalSelector), let swizzledMethod = class_getInstanceMethod(forClass, swizzledSelector) { if let originalMethod = class_getInstanceMethod(forClass, originalSelector), let swizzledMethod = class_getInstanceMethod(forClass, swizzledSelector) {
......
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