Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate presentModalViewController from right /left

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.

like image 906
user1085093 Avatar asked Jan 25 '12 08:01

user1085093


2 Answers

When present:

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:viewCtrl animated:NO];

When dismiss:

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];
like image 51
wcrane Avatar answered Oct 29 '22 21:10

wcrane


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];
like image 21
rakeshNS Avatar answered Oct 29 '22 19:10

rakeshNS