2

How can we get a pop transition effect when using a custom segue?

The following question has almost exactly what I need except I need to do a "previous" / "next" kind of animation.

Instead of push segue how to replace view controller (or remove from navigation stack)?

So, I tried to use CATransition work for us. It's not giving the right effect.

- (void)perform {

    UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];

    // Not quite what I want.
    // will make configurable (pop / push)
    CATransition *transition = [CATransition animation];
    transition.duration = 0.5;
    transition.type = kCATransitionReveal;

    [[[[sourceViewController view] window] layer] addAnimation:transition
                                                               forKey:kCATransitionReveal];


    // Grab Variables for readability
    UIViewController *destinationController = (UIViewController*)[self destinationViewController];
    UINavigationController *navigationController = sourceViewController.navigationController;

    // Get a changeable copy of the stack
    NSMutableArray *controllerStack = [NSMutableArray arrayWithArray:navigationController.viewControllers];
    // Replace the source controller with the destination controller, wherever the source may be
    [controllerStack replaceObjectAtIndex:[controllerStack indexOfObject:sourceViewController] withObject:destinationController];

    // Assign the updated stack with animation
    [navigationController setViewControllers:controllerStack animated:YES];
}
Community
  • 1
  • 1
finneycanhelp
  • 9,018
  • 12
  • 53
  • 77

0 Answers0