推送 UIViewController 的自定义动画

Custom Animation for Pushing a UIViewController(推送 UIViewController 的自定义动画)

本文介绍了推送 UIViewController 的自定义动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在推送视图控制器时显示自定义动画:我想实现类似展开"动画的效果,这意味着新视图从给定的矩形展开,假设在动画期间为 [100,100 220,380]全屏.

I want to show a custom animation when pushing a view controller: I would like to achieve something like an "expand" animation, that means the new view expands from a given rectangle, lets say [100,100 220,380] during the animation to full screen.

任何建议从哪里开始,分别是任何文档、教程、链接?:)

Any suggestions where to start, respectively any documents, tutorials, links? :)

好的.我可以使用以下代码制作展开动画:

Alright. I could make the expand animation with the following code:

if ([coming.view superview] == nil)   
    [self.view addSubview:coming.view];
    coming.view.frame = CGRectMake(160,160,0,0);
    [UIView beginAnimations:@"frame" context:nil];
    [UIView setAnimationDuration:4];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [coming viewWillAppear:YES];
    [going viewWillAppear:YES];
    coming.view.frame = CGRectMake(0, 0, 320, 480);
    [going viewDidDisappear:YES];
    [coming viewDidAppear:YES];
    [UIView commitAnimations];

我的视图已正确显示,但遗憾的是导航栏未更新.有没有办法手动做到这一点?

My View is properly displayed, but unfortunately the navigation bar is not updated. Is there a way to do that manually?

在示例代码中,一个函数在 0.03 秒内被调用,更新视图的转换.不幸的是,当推送 UIViewController 时,我无法调整视图框架的大小……是吗?

In the sample code, a function is called all 0.03 seconds that updates the transformation of the view. Unfortunately, when pushing a UIViewController, I am not able to resize the frame of the view ... am I ?

推荐答案

你可以做的是推送下一个视图控制器,但不要为它设置动画,如下所示:

What you could do is push the next view controller but don't animate it, like so:

[self.navigationController pushViewController:nextController animated:NO];

...然后,在被推入的视图控制器中,您可以使用 CoreAnimation 对其视图进行自定义动画.这可能最好在 viewDidAppear:(BOOL)animated 方法中完成.

...and then, in the view controller that is getting pushed in, you could do a custom animation of it's view using CoreAnimation. This might be best done in the viewDidAppear:(BOOL)animated method.

查看 核心动画指南 关于如何实际制作动画.尤其看隐式动画.

Check out the Core Animation Guide on how to actually do the animation. Look particularly at the implicit animation.

更新链接

这篇关于推送 UIViewController 的自定义动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:推送 UIViewController 的自定义动画

基础教程推荐