1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-11 13:15:35 +03:00

Ability to declare animation before scene attached to a view. fixes #54

This commit is contained in:
Victor Sukochev 2016-09-19 13:13:31 +06:00
parent 146756f094
commit 058c4634da
2 changed files with 20 additions and 0 deletions

View File

@ -3,6 +3,8 @@ let animationProducer = AnimationProducer()
class AnimationProducer {
var storedAnimations = [Node: BasicAnimation]()
func addAnimation(animation: BasicAnimation, withoutDelay: Bool = false) {
if animation.delay > 0.0 && !withoutDelay {
@ -24,6 +26,7 @@ class AnimationProducer {
}
guard let macawView = nodesMap.getView(node) else {
storedAnimations[node] = animation
return
}
@ -176,4 +179,19 @@ class AnimationProducer {
private func executeCompletion(emptyAnimation: BasicAnimation) {
emptyAnimation.completion?()
}
func addStoredAnimations(node: Node) {
if let animation = storedAnimations[node] {
addAnimation(animation)
storedAnimations.removeValueForKey(node)
}
guard let group = node as? Group else {
return
}
group.contents.forEach { child in
addStoredAnimations(child)
}
}
}

View File

@ -19,6 +19,7 @@ public class MacawView: UIView {
if let cache = animationCache {
self.renderer = RenderUtils.createNodeRenderer(node, context: context, animationCache: cache)
}
animationProducer.addStoredAnimations(node)
}
}
@ -43,6 +44,7 @@ public class MacawView: UIView {
if let cache = self.animationCache {
self.renderer = RenderUtils.createNodeRenderer(node, context: context, animationCache: cache)
}
animationProducer.addStoredAnimations(node)
let panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(MacawView.handlePan))
let rotationRecognizer = UIRotationGestureRecognizer(target: self, action: #selector(MacawView.handleRotation))