Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push ViewController with modal animation (horizontal flip)

I need to push a view controller to another view controller.

menuVC -> VC1 ->VC2

going from menuVC to VC1 requires no animation, but going from VC1 to VC2 and from VC2 to VC1 requires the flip animaton to occur.

However, when going from VC2 to menuVC, no animation is needed.

I am using the following code:

(from how to push a viewController with flip animation)

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
FlashCardVC *flashCardVC = [[FlashCardVC alloc] init];
[self.navigationController pushViewController:flashCardVC animated:NO];
[UIView commitAnimations];

The screen goes completely blank when I try and do the above.

What is wrong?

like image 374
stackOverFlew Avatar asked Feb 10 '13 11:02

stackOverFlew


2 Answers

You really should be using block based animations now. Also, if you're instantiating a storyboard controller from a controller that's also in the same storyboard, you can more easily access that storyboard with self.storyboard.

-(IBAction)flipToNext:(id)sender {
    SecondController *next = [self.storyboard instantiateViewControllerWithIdentifier:@"Next"];
    [self.navigationController pushViewController:next animated:NO];
    [UIView transitionWithView:self.navigationController.view duration:1 options:UIViewAnimationOptionTransitionFlipFromRight animations:nil completion:nil];
}
like image 112
rdelmar Avatar answered Sep 19 '22 20:09

rdelmar


Use these Extension in Swift 4.2

For push and pop view controller with horizontal flip Animation

extension UINavigationController {

    func pushViewControllerWithFlipAnimation(viewController:UIViewController){
        self.pushViewController(viewController
        , animated: false)
        if let transitionView = self.view{
            UIView.transition(with:transitionView, duration: 0.8, options: .transitionFlipFromLeft, animations: nil, completion: nil)
        }
    }

    func popViewControllerWithFlipAnimation(){
        self.popViewController(animated: false)
        if let transitionView = self.view{
            UIView.transition(with:transitionView, duration: 0.8, options: .transitionFlipFromRight, animations: nil, completion: nil)
        }
    }
}
like image 28
Avneesh Agrawal Avatar answered Sep 19 '22 20:09

Avneesh Agrawal