以下情况。
我有一个使用UINavigationController进行导航的应用程序。
对于特殊导航 Controller 的插入,我需要自定义动画,缩小。
到目前为止,我所看到的一切都很好,唯一的问题是,在动画开始之前“旧”的Viewcontroller消失了,因此新的Viewcontroller缩小了“无”,而不是在后台查看旧的Viewcontroller。
为了更好地查看,我创建了一个简单的示例应用程序:download
有人知道如何为新的viewcontroller(image3)设置动画,使旧的view controller(image1)在制作动画时处于背景中(image 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框架,但是推和创建 View Controller 正是Three20要做的。我只能钩到之间的部分(我的代码中的
THIS CAN BE CHANGED
)。在此之前和之后,我无法更改代码(除非进行大量研究)。 最佳答案
我很快就提出来了。这个想法是在比例动画完成后调用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];
}];
}