3

我正在使用以下方式展示一个视图控制器。代码:

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

我正在尝试为视图控制器的外观设置动画:传入的 VC 应该从当前显示的顶部覆盖 VC 向下滑动。遵循解决方案使其可以解决一个问题:在传入的 VC 出现在屏幕上之前,当前的 VC 消失了。有没有办法解决这个问题?也许有另一种解决方案来实现这种效果。

4

2 回答 2

3

试试这个代码:

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];

希望这会帮助你 。

于 2013-05-04T21:12:49.407 回答
0

试试下面的代码。您只需要从要显示 NewViewController 的位置调用以下方法。您需要做的是,您只需要更改NewViewcOntroller 的View Frame 的OriginY。

-(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];

 }
于 2013-05-04T18:57:01.347 回答