[英]UINavigationController stops animating when pushing controllers?
[英]Animating UIView while pushing a UINavigationController
以下情况。 我有一个使用 UINavigationController 进行导航的应用程序。
对于特殊导航 Controller 的推送,我想要一个自定义 Animation,缩小。 到目前为止,我所拥有的看起来不错,唯一的问题是,“旧”视图控制器在 animation 启动之前消失了,因此新视图控制器缩小了“无”而不是在后台查看旧视图控制器。
为了更好地查看,我创建了一个简单的示例应用程序:下载
有谁知道,如何为旧视图控制器(image1)在动画时保留在背景中的新视图控制器(image3)制作动画(图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
可以在我的代码中更改)之间的部分。 我不能在此之前和之后更改代码(除了大量研究)。
我很快就把它搞定了。 思路是在缩放animation完成后调用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];
}];
}
好的,执行此操作的一种方法(有点难看)是执行 animation 并在完成 animation 后执行 pushViewController。 当您执行 animation 时,您需要对即将呈现的视图控制器的屏幕进行动画处理。 由于 animation 以新视图结束,因此当新视图出现在屏幕上时,不会发生任何变化,因为它与刚刚的动画视图相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.