I have set up two view controllers in my Storyboard, each with an action button. I set up two segues:
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?
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.
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];
}
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];
}];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With