1

When we push any viewController, then the next controller comes from right to left. But when we present any view controller then the next controller comes from bottom to top. I want when we present any controller it comes from right to left same as that comes in pushing. I donot want to use modalViewController.

Saurabh Gulia
  • 285
  • 1
  • 3
  • 13

1 Answers1

3

While presenting controller use this code:

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

[self presentModalViewController:viewController animated:NO];

and when you dismiss, use this code:

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 dismissModalViewControllerAnimated:NO];
Salman Zaidi
  • 9,342
  • 12
  • 44
  • 61
  • Yes it is working, but transition in not as clean as it comes in pushing. It is not smooth and tidy. It actually wants to from bottom to top but then comes from right to left. – Saurabh Gulia Feb 03 '14 at 08:10
  • check that you are presenting and dismissing with "animated NO" property.. try different duration timings and choose what suits you best. – Salman Zaidi Feb 03 '14 at 09:07
  • 2
    @salman Zaidi I am getting a black shade while transition. How to resolve this ? – karthikPrabhu Alagu Jun 05 '16 at 00:52