Dilip Dilip - 10 months ago 54
iOS Question

How to change the animation direction of ViewController on PopViewController

Is it possible to change the Direction of ViewContoller Pop animation.

Right now when we push VC at the time it shows animation Slide Left-to-Right and on Pop Right-to-Left.

But i want animation Slide Left-to-Right on Pop VC.

I have tried to use


[UIView beginAnimations:nil context:NULL];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.75];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.navigationController.view cache:NO];
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:0.375];
[self.navigationController popViewControllerAnimated:NO];
[UIView commitAnimations];

But it doesn't have the animation i need which is Slide Left-to-Right. This is the animation i get

typedef enum {
} UIViewAnimationTransition;

Answer Source

I have used following code..

Add this in didFinishLaunchingWithOptions

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    //This line code needed so you will not see the back window when its popup, match it your app design.
    self.window.backgroundColor = [UIColor whiteColor];
    return YES;

Where your POP code add this code,

CATransition* transition = [CATransition animation];
transition.duration = 0.4f;
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.navigationController.view.layer addAnimation:transition
[self.navigationController popViewControllerAnimated:NO];