From 4baabd504b28367170f3b0a0d0a171486e3355d4 Mon Sep 17 00:00:00 2001 From: Luke Zhao Date: Tue, 7 Feb 2017 13:52:14 -0500 Subject: [PATCH] fix a regression with views not matching up --- .../AppleHomepage/AppleHomePage.storyboard | 10 +++++----- Sources/Hero.swift | 14 ++++++++------ Sources/HeroContext.swift | 11 +++++++---- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Examples/HeroExamples/Examples/AppleHomepage/AppleHomePage.storyboard b/Examples/HeroExamples/Examples/AppleHomepage/AppleHomePage.storyboard index 42de6efc..85ff4706 100644 --- a/Examples/HeroExamples/Examples/AppleHomepage/AppleHomePage.storyboard +++ b/Examples/HeroExamples/Examples/AppleHomepage/AppleHomePage.storyboard @@ -1,5 +1,5 @@ - + @@ -44,9 +44,9 @@ - + - + @@ -54,7 +54,7 @@ - + @@ -66,7 +66,7 @@ SERIES 2 - + diff --git a/Sources/Hero.swift b/Sources/Hero.swift index 5c1e702e..ec58cae7 100644 --- a/Sources/Hero.swift +++ b/Sources/Hero.swift @@ -300,18 +300,20 @@ internal extension Hero { // take a snapshot to hide all the flashing that might happen let completeSnapshot = fromView.snapshotView(afterScreenUpdates: true)! transitionContainer.addSubview(completeSnapshot) - - context = HeroContext(container:container, fromView: fromView, toView:toView) + + context = HeroContext(container:container) context.hide(view: toView) container.addSubview(toView) container.addSubview(fromView) - + toView.frame = fromView.frame toView.updateConstraints() toView.setNeedsLayout() toView.layoutIfNeeded() - + + context.set(fromView: fromView, toView: toView) + for processor in processors { processor.process(fromViews: context.fromViews, toViews: context.toViews) } @@ -338,8 +340,8 @@ internal extension Hero { if toView.layer.zPosition < fromView.layer.zPosition { // in this case, we have to animate the zPosition as well. otherwise the fade animation will be hidden. - context[toView]!.append(.zPosition(fromView.layer.zPosition)) - context[fromView] = [.zPosition(toView.layer.zPosition)] + context[toView]!.append(.zPosition(fromView.layer.zPosition + 1)) + context[fromView] = [.zPosition(toView.layer.zPosition - 1)] animatingViews[0].0.insert(fromView, at: 0) } } diff --git a/Sources/HeroContext.swift b/Sources/HeroContext.swift index bc8c497a..3e70555b 100644 --- a/Sources/HeroContext.swift +++ b/Sources/HeroContext.swift @@ -29,10 +29,13 @@ public class HeroContext { internal var viewAlphas = [UIView: CGFloat]() internal var targetStates = [UIView: HeroTargetState]() - internal init(container: UIView, fromView: UIView, toView: UIView) { + internal init(container: UIView) { + self.container = container + } + + internal func set(fromView:UIView, toView:UIView) { fromViews = HeroContext.processViewTree(view: fromView, container: container, idMap: &heroIDToSourceView, stateMap: &targetStates) toViews = HeroContext.processViewTree(view: toView, container: container, idMap: &heroIDToDestinationView, stateMap: &targetStates) - self.container = container } /** @@ -43,12 +46,12 @@ public class HeroContext { /** A flattened list of all views from source ViewController */ - public let fromViews: [UIView] + public var fromViews: [UIView]! /** A flattened list of all views from destination ViewController */ - public let toViews: [UIView] + public var toViews: [UIView]! } // public