Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push ViewController with slide effect from left to right? Animation name required

EDIT:

  • What is the animation name of the gif below (from right to left)?
  • What is the animation name of the complementary animation of the gif below (from left to right)?

NOTE: I don't want to push a segue. I want to push a view with that animation.


EDIT 2:

Some people are confused when I talk about animation names. However here is an example of an animation name that works (name is: UIViewAnimationTransitionFlipFromRight):

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

I am using push and pop to recall the actions on a stack. I believe that Navigation controller keeps the navigation in a stack style structure.


I am using a Navigation controller and I like the effect that I get when I go back (pop) to the previous view using the navigation bar item. It is a nice and smooth from right to left effect.

This is an example of a from right to left effect:

enter image description here

How can I create the complementary a from right to left effect? In other words when I go down in the view hierarchy?

This is how I push the view controller at the moment:

[self.navigationController pushViewController:view animated:YES];
like image 900
mm24 Avatar asked Nov 18 '25 13:11

mm24


1 Answers

We need to add CATransition animation for our viewController. look at this,

    add <CAAnimationDelegate> in your .h file

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    ViewController *VC = [storyboard instantiateViewControllerWithIdentifier:@ViewController"];
    CATransition *transition = [CATransition animation];
    transition.duration = 0.45;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
    transition.type = kCATransitionPush;
    transition.subtype = kCATransitionFromLeft;
    transition.delegate = self;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    [self.navigationController pushViewController:VC animated:NO];
like image 192
User558 Avatar answered Nov 21 '25 04:11

User558



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!