7

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;
Dilip Manek
  • 9,095
  • 5
  • 44
  • 56

6 Answers6

9

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)
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Sigex
  • 2,834
  • 2
  • 24
  • 25
6

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

Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
0

You can use [UIView beginAnimations:] for your case. setTransitionStyle as you need. check avalable UIViewAnimationTransitionStyle in apple documentation refer this https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html

Rugmangathan
  • 3,186
  • 6
  • 33
  • 44
  • Thanx for reply. Actually i have tried it but it doesnt have the animation i need which is Slide Left-to-Right. – Dilip Manek Feb 10 '14 at 06:07
  • I have used this http://stackoverflow.com/questions/2942221/how-to-change-pop-view-controller-animation-on-back-button code which is nice but doent contain animation i need. – Dilip Manek Feb 10 '14 at 06:08
0
let story = self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController")  as! SecondViewController

    UIView.beginAnimations("", context: nil)
    UIView.setAnimationDuration(1.0)
    UIView.setAnimationCurve(UIViewAnimationCurve.easeInOut)
    UIView.setAnimationTransition(UIViewAnimationTransition.flipFromRight, for: (self.navigationController?.view)!, cache: false)
    self.navigationController?.pushViewController(story, animated: true)
    UIView.commitAnimations()
Amul4608
  • 1,390
  • 14
  • 30
0

You could use completion block to do the job after animation:

UIView.animate(withDuration: 0.75, animations: { () -> Void in

     UIView.setAnimationCurve(UIViewAnimationCurve.easeInOut)
     self.navigationController?.popViewController(animated: true)

})
Yun CHEN
  • 6,450
  • 3
  • 30
  • 33
Nupur Sharma
  • 1,106
  • 13
  • 15
-1
 [UIView animateWithDuration:0.5f animations:^{
        self.myButton.transform = CGAffineTransformMakeScale(3, 3);
    } completion:^(BOOL finished){}];
    // for zoom out
    [UIView animateWithDuration:0.5f animations:^{

        self.myButton.transform = CGAffineTransformMakeScale(1, 1);
    }completion:^(BOOL finished){}];
    //View ANimation
    [UIView transitionWithView: self.navigationController.view
                      duration: 0.5
                       options: UIViewAnimationOptionTransitionCurlDown
                    animations: ^{

                        [self.navigationController popToRootViewControllerAnimated:YES];
                    }
                    completion: nil ];
Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
anji babu
  • 1
  • 2