iPhone UIView 动画最佳实践 [英] iPhone UIView Animation Best Practice
问题描述
在 iPhone 上动画视图转换的最佳实践是什么?
What is considered best practice for animating view transitions on the iPhone?
例如,来自苹果的 ViewTransitions
示例项目使用如下代码:
For example, the ViewTransitions
sample project from apple uses code like:
CATransition *applicationLoadViewIn = [CATransition animation];
[applicationLoadViewIn setDuration:1];
[applicationLoadViewIn setType:kCATransitionReveal];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
[[myview layer] addAnimation:applicationLoadViewIn forKey:kCATransitionReveal];
但也有一些代码片段在网络上漂浮,看起来像这样:
but there are also code snippets floating around the net that look like this:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:myview cache:YES];
[myview removeFromSuperview];
[UIView commitAnimations];
最好的方法是什么?如果您也可以提供一个片段,将不胜感激.
What is the best approach? If you could provide a snippet as well it'd be much appreciated.
注意:我一直无法让第二种方法正常工作.
NOTE: I've been unable to get the second approach to work correctly.
推荐答案
来自 UIView 参考关于beginAnimations:context:
方法的部分:
From the UIView reference's section about the beginAnimations:context:
method:
不鼓励在 iPhone OS 4.0 及更高版本中使用此方法.您应该改用基于块的动画方法.
Use of this method is discouraged in iPhone OS 4.0 and later. You should use the block-based animation methods instead.
例如基于 Tom's Comment 的基于块的动画
[UIView transitionWithView:mysuperview
duration:0.75
options:UIViewAnimationTransitionFlipFromRight
animations:^{
[myview removeFromSuperview];
}
completion:nil];
这篇关于iPhone UIView 动画最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!