stackOverFlew
stackOverFlew

Reputation: 1499

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?

Upvotes: 5

Views: 10227

Answers (3)

Avneesh Agrawal
Avneesh Agrawal

Reputation: 944

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)
        }
    }
}

Upvotes: 3

rdelmar
rdelmar

Reputation: 104082

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];
}

Upvotes: 18

stackOverFlew
stackOverFlew

Reputation: 1499

Great Answer: Showing pushviewcontroller animation look like presentModalViewController

(code)

    //UIViewController *yourViewController = [[UIViewController alloc]init];</s>

    [UIView  beginAnimations: @"Showinfo"context: nil];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    [self.navigationController pushViewController: yourViewController animated:NO];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
    [UIView commitAnimations];

However, this produced a blank screen also.

Instead, if you are using storyboards, it's best to instantiate through the storyboard:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle bundleForClass:[self class]]];

YourViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:@"yourViewControllerID"];

yourViewControllerID is set in storyboard under identity inspector for the yourviewcontroller class.

Upvotes: 1

Related Questions