I have the following set up:
The red controller has a method
- (IBAction)unwindToRed:(UISegue *)segue
and a
- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier
which returns a custom segue for this event.
In my custom segue I have the following in the perform code:
- (void)perform
{
// Just helpers to get the controllers from the segue
UIViewController *destination = self.destinationViewController;
UIViewController *source = self.sourceViewController;
// Setting transitioning delegate for custom transitions
destination.transitioningDelegate = self;
source.transitioningDelegate = self;
destination.modalTransitionStyle = UIModalPresentationCustom;
source.modalPresentationStyle = UIModalPresentationCurrentContext;
// When I am transitioning to a new one
if(!self.reversed)
{
[source presentViewController:destination animated:YES completion:nil];
}
// Or reversing from a current one
else
{
[source dismissViewControllerAnimated:YES completion:nil];
}
}
As you can see I have setup a transition delegate which which in turn calls
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
on an animation controller where I apply my custom animation. But now when I tap Unwind to Red on the yellow view, it only "unwinds" to its parent. (e.g the blue one).
When I leave the custom segue out of the equation it works just fine. It goes al the way to the top.
Now I think this has to do with the
[source dismissViewControllerAnimated:YES];
line, since that usually just goes "one up" my question is I think, what should I call there so it goes all the way up to red when needed? Yellow is a modal overlay. So "pop too root" would not work.
transitionContext
look like about the source, destination, frames and container? I think you shouldn't use[source dismissViewControllerAnimated:YES];
, you should just call[transitionContext completeTransition:YES];
– Fábio Oliveira