0

Working on an objective-c video project. On the video player I have a button that returns the user back to a menu screen.

In my PlayerViewController.m, I have:

- (IBAction)unloadPlayer:(id)sender
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

It works, however it pushes the screen from the top down. What I would like to do is push in from the left to right. How can this be done?

Thanks!

dace
  • 5,819
  • 13
  • 44
  • 74
  • writing your own segue is one solution. – meth Feb 02 '16 at 16:42
  • When you presented it, didn't it come in from the bottom? If so, won't it look weird to be dismissed this way? If you want it to be dismissed by going to the right, you can change the presentation to a non-modal push and it will come in from the right (and dismiss the way you want automatically) – Lou Franco Feb 02 '16 at 16:44

2 Answers2

2

You can use custom animation while dismissing your viewcontroller. This will solve your problem.

CATransition *transition = [CATransition animation];
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromLeft;
[self.view.window.layer addAnimation:transition forKey:nil];
[self dismissViewControllerAnimated:NO completion:nil];
rushisangani
  • 3,195
  • 2
  • 14
  • 18
0

Swift 2:

let transition: CATransition = CATransition()
transition.duration = 0.3
transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromLeft
self.view.window!.layer.addAnimation(transition, forKey: nil)
self.dismissViewControllerAnimated(false, completion: { _ in })

But I recommend to use this:

UIView.transitionWithView(self.view, duration: 0.325, options: UIViewAnimationOptions.CurveEaseInOut, animations: {

    // animation

    }, completion: { (finished: Bool) -> () in

    // completion

    })
Alvin George
  • 14,148
  • 92
  • 64