Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Present ViewController with custom animation

I am presenting a view controller using the foll. code:

VC_B * b = [[VC_B alloc] init...];
[self presentViewController:b animated:YES completion:nil];

I am trying to animate appearance of the view controller: the incoming VC should slide down from top covering VC that is currently displayed. following this solution makes it work with one problem: current VC disappears before the incoming VC appears on the screen. Is there a way to resolve this? perhaps there is an alternative solution to achieve this effect.

like image 409
Asahi Avatar asked Aug 31 '26 16:08

Asahi


1 Answers

Try this code :

CreateNewViewController *newViewController = [[CreateNewViewController alloc]initWithNibName:@"CreateNewViewController" bundle:nil];

    CATransition *transition = [CATransition animation];
    transition.duration = 0.05;
    transition.timingFunction = [CAMediaTimingFunction      
    functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type =kCATransitionMoveIn;
    transition.subtype =kCATransitionFromTop;

    transition.delegate   = self;

    [self presentModalViewController:newViewController animated:NO];
    [self.view insertSubview:newViewController.view atIndex:0];

    [self.view.layer addAnimation:transition forKey:nil];

Hope this will help you .

like image 126
Gaurav Rastogi Avatar answered Sep 04 '26 05:09

Gaurav Rastogi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!