Alex Rivera | Logout

Animate presentModalViewController from right /left

Asked 2012-01-25T08:55:57.647
25

Currently I am using [self presentModalViewController :newVC animated:YES] .I want to present newViewcontroller from left/right/top/bottom with a push effect. I tried to use CATransition but it displays a black screen in between the transition.

Edit
Report

1 Answer

3

I had the same problem. Say you want to present a view controller 2 from view controller 1. In the first view controller use

 [self presentModalViewController: controller animated: NO]];

In the second view controller, in viewWillAppear: method add the code

    CATransition *animation = [CATransition animation];

    [animation setDelegate:self];
    [animation setType:kCATransitionPush];
    [animation setSubtype:kCATransitionFromRight];

    [animation setDuration:0.40];
    [animation setTimingFunction:
     [CAMediaTimingFunction functionWithName:
      kCAMediaTimingFunctionEaseInEaseOut]];


    [self.view.layer addAnimation:animation forKey:kCATransition];

It will work fine. If black screen comes again, if you are using navigation controller, replace

   [self.view.layer addAnimation:animation forKey:kCATransition];

with

   [self.navigationController.view.layer addAnimation:animation forKey:kCATransition];
answered 2012-01-25T09:59:41.400

Your Answer