From dcadb01c4ae3c837aa1feff3af9e303ebbfb1996 Mon Sep 17 00:00:00 2001 From: Viktor Sukochev Date: Thu, 2 Feb 2017 17:34:22 +0700 Subject: [PATCH] Groups hierarhy transformation --- .../Examples/Morphing/MorphingView.swift | 50 +++++++++++++++---- .../animation/types/MorphingAnimation.swift | 27 ++++++++++ 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/Example/Example/Examples/Morphing/MorphingView.swift b/Example/Example/Examples/Morphing/MorphingView.swift index 5d833e85..96bfb27a 100644 --- a/Example/Example/Examples/Morphing/MorphingView.swift +++ b/Example/Example/Examples/Morphing/MorphingView.swift @@ -15,6 +15,18 @@ class MorphingView: MacawView { class func newScene() -> Node { + + /* + let form1 = Rect(x: 50.0, y: 50.0, w: 200.0, h: 200.0) + let form2 = Circle(cx: 150.0, cy: 150.0, r: 100.0) + + let shape = Shape(form: form1) + let animation = shape.formVar.animation(to: form2, during:1.5, delay: 2.0) + animation.autoreversed().play()//.cycle().play() + + return shape + */ + /* let group1 = [ Shape(form: Line(x1: 90.0, y1: 110.0, x2: 210.0, y2: 110.0), stroke: Stroke(width: 6.0, cap: .round)), @@ -28,24 +40,42 @@ class MorphingView: MacawView { Shape(form: Line(x1: 90.0, y1: 210.0, x2: 210.0, y2: 90.0), stroke: Stroke(width: 6.0, cap: .round)) ].group() + group1.contentsVar.animate(to: group2) + + return group1 */ + + + + let stroke = Stroke(width: 15.0, cap: .round) + let group1 = [ - Shape(form: Line(x1: 90.0, y1: 110.0, x2: 210.0, y2: 110.0), stroke: Stroke(width: 15.0, cap: .round)), - Shape(form: Line(x1: 90.0, y1: 150.0, x2: 210.0, y2: 150.0), stroke: Stroke(width: 15.0, cap: .round)), - Shape(form: Line(x1: 90.0, y1: 190.0, x2: 210.0, y2: 190.0), stroke: Stroke(width: 15.0, cap: .round)), + Shape(form: Line(x1: 90.0, y1: 110.0, x2: 210.0, y2: 110.0), stroke: stroke), + [Shape(form: Line(x1: 90.0, y1: 150.0, x2: 210.0, y2: 150.0), stroke: stroke), + Shape(form: Line(x1: 90.0, y1: 190.0, x2: 210.0, y2: 190.0), stroke: stroke)].group(), ].group() let group2 = [ - Shape(form: Line(x1: 110.0, y1: 150.0, x2: 135.0, y2: 125.0), stroke: Stroke(width: 15.0, cap: .round)), - Shape(form: Line(x1: 110.0, y1: 150.0, x2: 190.0, y2: 150.0), stroke: Stroke(width: 15.0, cap: .round)), - Shape(form: Line( x1: 110.0, y1: 150.0, x2: 135.0, y2: 175.0), stroke: Stroke(width: 15.0, cap: .round)), - Shape(form: Circle(cx: 150.0, cy: 150.0, r: 100.0), stroke: Stroke(width: 6.0, cap: .round)) + [Shape(form: Line(x1: 110.0, y1: 150.0, x2: 135.0, y2: 125.0), stroke: stroke), + Shape(form: Line(x1: 110.0, y1: 150.0, x2: 190.0, y2: 150.0), stroke: stroke)].group(), + Shape(form: Line( x1: 110.0, y1: 150.0, x2: 135.0, y2: 175.0), stroke: stroke), ].group() - let anim = group1.contentsVar.animation(to: group2, during: 0.5, delay: 2.0) - anim.easing(.easeIn).play() + let presentedGroup = [ + Shape(form: Line(x1: 90.0, y1: 110.0, x2: 210.0, y2: 110.0), stroke: stroke), + Shape(form: Line(x1: 90.0, y1: 150.0, x2: 210.0, y2: 150.0), stroke: stroke), + Shape(form: Line(x1: 90.0, y1: 190.0, x2: 210.0, y2: 190.0), stroke: stroke), + ].group() - return group1 + [ + presentedGroup.contentsVar.animation(to: group2, during: 10.0, delay: 5.0), + //presentedGroup.contentsVar.animation(to: group1, during: 0.5, delay: 2.0), + ].sequence().play() + + return presentedGroup + + + } } diff --git a/Source/animation/types/MorphingAnimation.swift b/Source/animation/types/MorphingAnimation.swift index e1a5fb86..b68941ec 100644 --- a/Source/animation/types/MorphingAnimation.swift +++ b/Source/animation/types/MorphingAnimation.swift @@ -80,6 +80,7 @@ public extension AnimatableVariable where T: GroupInterpolation { fromNode = passedFromNode } + // Shapes on same hierarhy level let fromShapes = fromNode.contents.flatMap{$0 as? Shape} let toShapes = to.contents.flatMap{$0 as? Shape} let minPathsNumber = min(fromShapes.count, toShapes.count) @@ -111,6 +112,32 @@ public extension AnimatableVariable where T: GroupInterpolation { } } + // Groups on same hierahy level + let fromGroups = fromNode.contents.flatMap{$0 as? Group} + let toGroups = to.contents.flatMap{$0 as? Group} + let minGroupsNumber = min(fromGroups.count, toGroups.count) + for i in 0..