Dilip Dilip - 1 month ago 14
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

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;

Answer

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
                                            forKey:kCATransition];
[self.navigationController popViewControllerAnimated:NO];
Comments