iPhone UIView动画最佳实践 [英] iPhone UIView Animation Best Practice
问题描述
在iPhone上动画视图转换的最佳做法是什么?
What is considered best practice for animating view transitions on the iPhone?
例如,来自apple的 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:上下文:
方法:
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的评论的基于块的动画>
Eg of Block-based Animation based on Tom's Comment
[UIView transitionWithView:mysuperview
duration:0.75
options:UIViewAnimationTransitionFlipFromRight
animations:^{
[myview removeFromSuperview];
}
completion:nil];
这篇关于iPhone UIView动画最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!