4

以下情况。 我有一个应用程序使用UINavigationController进行导航。在推送UINavigationController时动画UIView

对于推动一个特殊的导航控制器我想要一个自定义的动画,缩小。 我现在看起来不错,唯一的问题是,“老”Viewcontroller在动画开始之前消失,所以新的viewcontroller放大了“没有”,而不是在后台查看旧的viewcontroller。

为了更好地观看我创建了一个简单的示例应用程序:download

enter image description hereenter image description hereenter image description here

有谁知道,如何动画新视图 - 控制(图像3)旧视图控制器(图像1)保持在动画背景(图片2)?

/* THIS CANNOT BE CHANGED */ 
    AnimatedViewController *animatedViewController = [[AnimatedViewController alloc] initWithNibName:@"AnimatedViewController" bundle:nil]; 

    /* THIS CAN BE CHANGED */ 
    animatedViewController.view.transform = CGAffineTransformMakeScale(0.01, 0.01); 
    [UIView beginAnimations:@"animationExpand" context:NULL]; 
    [UIView setAnimationDuration:0.6f]; 
    animatedViewController.view.transform=CGAffineTransformMakeScale(1, 1); 
    [UIView setAnimationDelegate:self]; 
    [UIView commitAnimations]; 

    /* THIS CANNOT BE CHANGED */ 
    [self.navigationController pushViewController:animatedViewController animated:NO]; 

附加信息:我的应用程序并不那么简单。我为我的应用程序使用了three20框架,但视图控制器的推动和创建正是three20所做的。我只能钩进(我的代码中的THIS CAN BE CHANGED)之间的部分。我无法在此之前和之后更改代码(除了大量研究)。

+0

如何设置相同的动画(启示方向),同时弹出到原始视图..? – 2013-03-06 14:37:32

回答

9

我非常快速地鞭打它。这个想法是在缩放动画完成后调用pushViewController。

-(IBAction)animateButtonClicked:(id)sender { 
    animatedViewController = [[AnimatedViewController alloc] initWithNibName:@"AnimatedViewController" bundle:nil]; 
    animatedViewController.view.transform = CGAffineTransformMakeScale(0.01, 0.01); 

    [UIView animateWithDuration:0.6 
        animations:^{ 
         [self.view addSubview:animatedViewController.view]; 
         animatedViewController.view.transform=CGAffineTransformMakeScale(1, 1);      
        } 
        completion:^(BOOL finished){ 
         [animatedViewController.view removeFromSuperview]; 
         [self.navigationController pushViewController:animatedViewController animated:NO]; 
        }]; 

} 
+0

是的,这工作正常(在我的示例应用程序)。但我有一个问题在我的应用程序中使用它。我只能在委托回调中工作:https://gist.github.com/f13b1da4114b7d8691d6在这个委托pushviewcontroller被称为 – choise 2011-05-03 20:47:47

+0

后,这里的问题是,该视图被渲染两次。 – choise 2011-05-03 20:53:14

+0

@choise,所以你说的是你不能从函数返回,直到缩放动画完成(即等待0.6秒),因为之后直接调用pushViewController? – 2011-05-03 21:07:39

0

好,要做到这一点(有点难看)的一种方式是做动画,在动画完成后,执行pushViewController。当您进行动画制作时,您需要动画化将要呈现的视图控制器屏幕的外观。由于动画以新视图结束,所以当新视图进入屏幕时,不应该改变,因为它与刚才的动画视图相同。

相关问题