3

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.

Community
  • 1
  • 1
Asahi
  • 13,378
  • 12
  • 67
  • 87

2 Answers2

3

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 .

Gaurav Rastogi
  • 2,145
  • 1
  • 14
  • 19
0

Try the below code. You just need to call below method from the point where you want to display NewViewController. What you need to do is that you just need to change the OriginY of NewViewcOntroller's View Frame.

-(void)displayNewVC
 {

 YourNewViewController *newVC = [[YourNewViewController alloc] init];

CGFloat originY = -450;//set originY as you want to display newViewController from the Top to bottom with animation
//initially set originY out of the Frame of CurrentViewcontroller
newVC.view.frame = CGRectMake(orginX, originY, newVC.view.frame.size.width, newVC.view.frame.size.height);

/*Display View With Animation*/
 originY = 300;
[UIView animateWithDuration:.3 animations:^{
     //set new originY as you want.
    newVC.view.frame = CGRectMake(orginX, originY, newVC.view.frame.size.width,  newVC.view.frame.size.height);
    
 } completion:NULL];

 [currentViewController.view addSubview:newVC.view];

 }
halfer
  • 19,824
  • 17
  • 99
  • 186
Kamar Shad
  • 6,089
  • 1
  • 29
  • 56