15

Lets say I have 3 UIViewController's - A, B and C. The transitions between A<->B and B<->C are done with different animated transitioning in both ways - forward and backward (unwind segue animation) subclassing UIViewControllerTransitioningDelegate and UIViewControllerAnimatedTransitioning. The transitions with just one step forward or backward work perfectly, but when I try to unwind more than one step back from C->A (like home button) - B is shown without animation and then B->A custom animation is played, which is weird looking. viewWillApper is called for all middle view controllers on the chain (in my example B). It is almost like unwind from C->A is done this way - C->B->A instead of C->A (with one note - that only B->A animation is played, C->B animation is not played). What I want is just C->A (not B->A) animation, without showing any of other middle view controllers or calling their viewWillAppear methods. I want to be able to set custom unwind segue animation for C->A. How can I do that?

NOTE 1: I don't embed my controllers in UINavigationController and I preffer not to, because as far as I know (correct me if I'm wrong) it is not very flexible or at least scalable for different custom animations between different steps. Neither way I prefer not to use it.

NOTE 2: I've tried to override

override func segueForUnwindingToViewController(toViewController: UIViewController, fromViewController: UIViewController, identifier: String?) -> UIStoryboardSegue

in A and return custom segue (UIStoryboardSeguederived class) for the unwinding from C->A. The method was called, but the animation is starting and in the middle of it switch to B->A animated transition delegate animation (which I have set for transitioning between B->A). So this is not working also.

What I'm doing wrong? I'm pretty sure that Apple developers have this figured it out and made some sort of API or something like that. There is nothing in the Apple documentation about how to unwind few steps back with custom animation.

And one last thing unwind segue few steps back is working perfectly, just the custom animation is not or at least I can't make it work.

Any help will be highly appreciated.

devfreak
  • 1,201
  • 2
  • 17
  • 27
  • can you add your code, or the skeleton of it somewhere? I may have an idea in how to do what you want – Icaro Jun 08 '15 at 03:19
  • This seems to discuss what you are trying to do. In particular skipping intermediate controllers. http://stackoverflow.com/questions/26785511/how-to-unwind-through-multiple-views-without-displaying-intermediate-views – Rory McKinnel Jun 08 '15 at 11:48
  • The skeleton is the same as in [link](http://stackoverflow.com/questions/26785511/how-to-unwind-through-multiple-views-without-displaying-intermediate-views). And yeah this solution will fix my problem (using UINavigationController), I just wondered if there is another way, I don't want to make my one navigation controller master of everything, I want to decouple the navigation controllers as much as possible, including their transactions. – devfreak Jun 08 '15 at 15:14

2 Answers2

1

I understand that in your question you clearly stated that you do not want to use UINavigationController, and I understand this. So need to accept this answer.

But I would still promote using the UINavigationController in this scenario, as it offer a lot of help tracking navigation, and is actually very flexible if extended, and even offers custom transitions via UINavigationControllerDelegate and UIViewControllerAnimatedTransitioning.

When it comes to navigating you can manually manipulate the navigation stack, using .pushToViewController() and .popViewController() or directly manipulating the list of controllers in .viewControllers or popToRootController().

I have used UIKit and UINavigationController in a game that needed quite heavy transitions, and in my opinion it could take a lot of customization and still offer a great deal of help with navigation.

Mikael Hellman
  • 2,664
  • 14
  • 22
  • Yes you are right I know that adding `UINavigationController` will fix the issue for me, I can even inherit it and override `segueForUnwindingToViewController` to return Custom Unwind Segue to animate between C and A, but that is just over complicating the code, making navigation controller master of all. It has to know about every controller in the app – devfreak Jun 08 '15 at 15:18
1

Check out the following video from this year's WWDC(around the 30 min mark). There's a link to sample code at the bottom as well.

https://developer.apple.com/videos/wwdc/2015/?id=215

You might need to wait for iOS 9 though :)

Good luck!

nananta
  • 479
  • 4
  • 7