用于推送 UIViewController 的自定义动画
我想在推动视图控制器时显示自定义动画:我想实现类似“展开”动画的效果,这意味着新视图从给定的矩形展开,例如在动画到全屏期间的[100,100 220,380]。
有什么建议从哪里开始,分别有什么文档、教程、链接吗? :)
好吧。我可以使用以下代码制作展开动画:
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];
我的视图已正确显示,但不幸的是导航栏未更新。有没有办法手动执行此操作?
在示例代码中,调用了一个函数,该函数花费了 0.03 秒来更新视图的转换。 不幸的是,当推送 UIViewController
时,我无法调整视图框架的大小......是吗?
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?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我使用以下函数(添加到 UINavigationController 中)来自定义推送动画:
我想您可以调整此代码来执行您想要的任何动画。
I use the following function (added to
UINavigationController
) to customize the push animation:I guess you could adapt this code to do whatever animation you want.
您正在寻找的代码:
The code which you are looking for:
您可以做的是推送下一个视图控制器,但不要对其进行动画处理,如下所示:
...然后,在被推入的视图控制器中,您可以使用 CoreAnimation 对其视图执行自定义动画。这可能最好在
viewDidAppear:(BOOL)animated
方法中完成。查看 核心动画指南,了解如何实际制作动画。特别注意隐式动画。
编辑: 已更新链接
What you could do is push the next view controller but don't animate it, like so:
...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.
EDIT: updated link
@zoul:效果很好!我刚刚将“self”更改为“self.navigationController”,将“self.view”更改为“self.navigationController.view”不知道是否有必要,但它有效。 @crafterm,至于弹出,只需在 viewDidLoad 或 ViewWillAppear 中添加以下代码来制作您自己的 leftBarButtonItem:
然后我只是调整了推送功能并制作了我在 -backButtonTapped 方法中调用的 popWithTransition 函数。
请注意,在动画之后,popViewController 调用已向下移动到末尾。不知道这是否符合犹太洁食,但它再次起作用了。
@zoul: That worked great! I just changed "self" to "self.navigationController" and "self.view" to "self.navigationController.view" Don't know if that was necessary, but it worked. And @crafterm, as for popping back, just make your own leftBarButtonItem by adding this code in viewDidLoad or ViewWillAppear:
Then I just tweaked the push function and made this popWithTransition function that I called in my -backButtonTapped method.
Note that the popViewController call got shifted down to the end, after the animation. Don't know if that's kosher, but again, it worked.
您需要下载 iPhone 开发人员指南的第 2 章。具体查看 affineRotate 示例,尽管任何核心 animatin 示例都会对您有所帮助。
What you want is the downloads for chapter 2 of iphone developers cookbook. Look at the affineRotate sample specifically, although any of the core animatin samples will help you.
看看 ADTransitionController,它是具有自定义过渡动画的 UINavigationController 的替代品(其 API 与 API 匹配) UINavigationController)是我们在 Applidium 创建的。
您可以为push和pop操作使用不同的预定义动画,例如滑动、淡入淡出、立方体、卡鲁塞尔等等。就您而言,您请求的动画是名为“Zoom”的动画。
Have a look at ADTransitionController, a drop in replacement for UINavigationController with custom transition animations (its API matches the API of UINavigationController) that we created at Applidium.
You can use different pre-defined animations for push and pop actions such as Swipe, Fade, Cube, Carrousel and so on. In your case, the animation you are requesting is the one called Zoom.