0

Assume that we have 3 view controllers: A, B, and C. A is the root view controller, which has presented B, and B has in turn presented C. How can we perform a custom unwind segue from C to A that does not reveal B?

A - B - C

A UIStoryboardSegue has a reference to its source view controller as well as its destination view controller, but what about the view controllers in between (B in our example)? We can perform whatever animations we want on C, but I don't see how we can affect B in any way.

The goal is simply to dismiss all but the root (B and C) to the right while having A come in from the left, so both source and destination are swiping horizontally next to each other. B should not be visible at any point of the animation.

My example dismisses only two views, but I hope to find a solution that would apply to an arbitrary number of views. Furthermore, I am not interested in solving this using a UINavigationController. I have tried simply dismissing B, which does indeed dismiss C as well, but you can still see both B and C during the animation.

Daniel Larsson
  • 6,278
  • 5
  • 44
  • 82
  • You can take a look at Unwind Segues. Here is the example [Unwind Segues in iOS Storyboards](https://spin.atomicobject.com/2014/10/25/ios-unwind-segues/). – aNa12 Apr 28 '17 at 05:46
  • The question is about unwind segues. – Daniel Larsson Apr 28 '17 at 05:48
  • So, have you try doing it as in the example? – aNa12 Apr 28 '17 at 05:56
  • The example is just on how to use unwind segues in general. They are not creating any custom animations. I understand how to make an unwind segue, that is not the issue. – Daniel Larsson Apr 28 '17 at 05:58
  • http://stackoverflow.com/questions/26785511/how-to-unwind-through-multiple-views-without-displaying-intermediate-views – aNa12 Apr 28 '17 at 06:09

1 Answers1

0

You can dissmiss your controller as below :

    self.presentingViewController?.presentingViewController?.dismiss(animated: true, completion: nil) // you need to track viewcontroller's stack hierarchy
KKRocks
  • 8,222
  • 1
  • 18
  • 84
  • I can't seem to perform a custom dismiss animation without revealing the middle view during the animation, as stated in the last sentence of the question. – Daniel Larsson Apr 25 '17 at 16:33
  • did you try first ? – KKRocks Apr 25 '17 at 16:37
  • Again, as stated in the question: "I have tried simply dismissing B, which does indeed dismiss C as well, but you can still see both B and C during the animation" – Daniel Larsson Apr 25 '17 at 16:38
  • Are you using a custom UIViewControllerAnimatedTransitioning? If so, could you show me how you perform animations on all dismissing views and not just on the bottom-most one? – Daniel Larsson Apr 25 '17 at 17:51
  • The documentation for dismiss:animated: says "only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack." – Daniel Larsson Apr 25 '17 at 18:44