Dirección de giro horizontal en guiones gráficos de iOS

I have set up two view controllers in my Storyboard, each with an action button. I set up two segues:

  1. From the first view controller to the second view controller: Modal, Flip Horizontal.
  2. From the second view controller to the first view controller: Modal, Flip Horizontal.

Everything works, but I would like it to flip one way and back, now it flips the same direction for both view controllers.

What is the easiest way to make a flip-flip back effect?

preguntado el 22 de mayo de 12 a las 12:05

3 Respuestas

I encountered the same problem, and hopefully found a solution.

I used a custom segue to flip the way back. Here is the code of my FlipLeftSegue

@implementation FlipLeftSegue
- (void)perform
{
    UIViewController *src = (UIViewController *) self.sourceViewController;
    UIViewController *dst = (UIViewController *) self.destinationViewController;    

    [UIView beginAnimations:@"LeftFlip" context:nil];
    [UIView setAnimationDuration:0.8];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:src.view.superview cache:YES];
    [UIView commitAnimations];

    [src presentViewController:dst animated:NO completion:nil];
}
@end

The only problem I found to this solution, is that the viewDidAppear method is called immediatly when the animation starts. Whereas with normal segue, it is called after the animation.

contestado el 23 de mayo de 12 a las 15:05

This is because you are braking the view controller hierarchy. Use UIViewcontroller transitionViewController: ... - doozMen

Instead of creating a new presentation of a ViewController, I'd suggest accessing the property for presentingViewController on the second ViewController, and then calling -dismissViewControllerAnimated:completion: on it. Like so:

-(IBAction)someResponderToYourCancelButtonOrWhatever:(id)sender {
    // Do some stuff
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}

Respondido 10 Abr '13, 06:04

You better use this code in NSZombie's answer:

- (void)swapChildVCFrom:(UIViewController *)from to:(UIViewController *)to options:(enum UIViewAnimationOptions)options
{
    [self addChildViewController:to];
    [from willMoveToParentViewController:nil];

    // Adjust the new child view controller's view's frame
    // For example here just set it to fill the parent view
    to.view.frame = self.view.bounds;

    [self transitionFromViewController:from
                      toViewController:to
                              duration:1.0
                               options:options
                            animations:nil
                            completion:^(BOOL b)
                            {
                                [to didMoveToParentViewController:self];
                                [from.view removeFromSuperview];
                                [from removeFromParentViewController];
                            }];
}

contestado el 29 de mayo de 14 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.