0

Right now I am using a segue from storyboard to push a view controller and there is just the one push transition. How can I imitate the "Pop" transition in code? Can I do this while still using storyboard for my other transitions in place now?

UPDATE

I tried what is suggested in the first comment here, with some changes. Here's what I have:

UIViewController *dst = [self destinationViewController];
UIViewController *src = [self sourceViewController];
[dst viewWillAppear:YES];
[dst viewDidAppear:NO];

CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGRect f = CGRectMake(-screenBounds.size.width, 0, screenBounds.size.width, screenBounds.size.height);
dst.view.frame = f;
f.origin.x = screenBounds.size.width;
src.view.frame = f;

[UIView transitionFromView:src.view
                    toView:dst.view
                  duration:0.3
                   options:UIViewAnimationOptionTransitionNone
                completion:^(BOOL finished){
     [dst viewDidAppear:YES];

     UINavigationController *nav = src.navigationController;
     [nav popViewControllerAnimated:NO];
     [nav pushViewController:dst animated:NO];
 }];

This is working almost how I want, but the original viewcontroller is just disappearing instead of sliding to the right.

SirRupertIII
  • 12,324
  • 20
  • 72
  • 121

1 Answers1

0

You can create Segue type "Custom" on your stroyboard and create a new UIStoryboardSegue class named "popSegue" In the popSegue.m file add this:

    -(void)perform{
UIViewController *sourceViewContreoller = [self sourceViewController];

CATransition *animation = [CATransition animation];
[animation setType:kCATransitionFromLeft]; //or kCATransitionFromRight 
[animation setDuration:0.25];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:
                              kCAMediaTimingFunctionEaseIn]];

[sourceViewContreoller.navigationController.view.layer addAnimation:animation forKey:@"animateOpacity"]; //or key=@"fadeTransition"

[sourceViewContreoller.navigationController popViewControllerAnimated:YES];

[CATransaction commit];
}

In the storyboard editor Select the segue and change the Segue Class to "popSegue". Set the Identifier to "popSegue". Try this and comment for your result

Kepler
  • 705
  • 1
  • 5
  • 19
  • I'm actually wanting to push a view, but with the transition of a pop. So the pushed view will come from the left to the right. Sorry, in the description, I meant left to right, just made a change. – SirRupertIII Aug 17 '13 at 20:44
  • This is just popping the navcontroller. I want to push a view controller, but have the transition look like it is popping. – SirRupertIII Aug 18 '13 at 17:59