Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dismiss modal ViewController from right to left?

In Objective-C, I want to dismiss modal ViewController from right to left.

Now I can move from left to right on modal. But I don't know how to dismiss this modal VC from left to right like push screen transition.

Here is a code which moves from a-ViewController to b-ViewController.

bViewController *nextVC = [[bViewController alloc] initWithNibName:nil bundle:nil];

CATransition *transition = [CATransition animation];
transition.duration = 0.5; 
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
transition.type = kCATransitionPush ; 
[transition setSubtype:kCATransitionFromLeft];
[[nextVC.view layer] addAnimation:transition forKey:@"TransitionTest"]; 
//[self presentViewController:nextVC animated:YES completion:nil];
//if it's possible, I want to use upside's cord.(don't addSubView) but I don't know how to do it)
[self.view addSubview:nextVC.view] ;
like image 209
K.K.D Avatar asked Feb 29 '16 07:02

K.K.D


People also ask

How do I dismiss a presented ViewController?

When it comes time to dismiss a presented view controller, the preferred approach is to let the presenting view controller dismiss it. In other words, whenever possible, the same view controller that presented the view controller should also take responsibility for dismissing it.


1 Answers

Objective-C

CATransition *transition = [CATransition animation];
transition.duration = 0.4;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromRight;
[self.view.window.layer addAnimation:transition forKey:nil];
[self dismissViewControllerAnimated:NO completion:nil]; 

Swift 5

let transition = CATransition()
transition.duration = 0.5
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.type = CATransitionType.push
transition.subtype = CATransitionSubtype.fromRight
self.view.window!.layer.add(transition, forKey: nil)
self.dismiss(animated: false, completion: nil)
like image 102
Mandeep Kumar Avatar answered Oct 26 '22 06:10

Mandeep Kumar