Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 UIViewAnimationTransition.

[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 {
   UIViewAnimationTransitionNone,
   UIViewAnimationTransitionFlipFromLeft,
   UIViewAnimationTransitionFlipFromRight,
   UIViewAnimationTransitionCurlUp,
   UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;
like image 426
Dilip Avatar asked Feb 10 '14 05:02

Dilip


2 Answers

Cheers, here is the swift 3.0 ~ 4.0 version.

let transition = CATransition()
transition.duration = 0.4
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
self.navigationController?.view.layer.add(transition, forKey: kCATransition)
self.navigationController?.popViewController(animated: false)
like image 116
Sigex Avatar answered Oct 07 '22 10:10

Sigex


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 of code needed so you will not see the back window when its pop, match it with 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
                                            forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];

Check the result in this GIF,
http://www.giphy.com/gifs/l2YSeBELE1phMEd5S

like image 39
Dilip Avatar answered Oct 07 '22 11:10

Dilip