iOS 4.2 上的这个动画有什么问题吗?
我在我的项目上创建了在 2 个 UIWebView 之间交换的动画。 当我在 iOS 3.2 上进行开发时,动画一切都很好。 但当我转向 iOS 4.2 时,突然一切都出了问题:
//LeftView Animation
[UIView beginAnimations:@"leftPortrait" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:leftView cache:YES];
[leftWebView setFrame:CGRectMake(0, 0, 384, 916)];
[UIView commitAnimations];
//RightView Animation
[UIView beginAnimations:@"rightPortrait" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:rightView cache:YES];
[rightWebView setFrame:CGRectMake(0, 0, 384, 916)];
[UIView commitAnimations];
谢谢!
I created animation on my project that swaps between 2 UIWebView.
When I was developing on iOS 3.2 everything was fine with the animation.
But when I moved to iOS 4.2 suddenly everything goes wrong:
//LeftView Animation
[UIView beginAnimations:@"leftPortrait" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:leftView cache:YES];
[leftWebView setFrame:CGRectMake(0, 0, 384, 916)];
[UIView commitAnimations];
//RightView Animation
[UIView beginAnimations:@"rightPortrait" context:nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.0f];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:rightView cache:YES];
[rightWebView setFrame:CGRectMake(0, 0, 384, 916)];
[UIView commitAnimations];
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用基于块的动画。
它们更干净、更流畅,也是当前苹果的做事方式。从 [UIView beginAnimations:context:] 切换到基于块的动画最近还修复了我的代码中的动画问题。
在您的情况下,一个简单的基于块的动画版本将是
[UIView animateWithDuration:1.0fanimations:^{[leftWebView setFrame:CGRectMake(0, 0, 384, 916)];}
。您可能需要使用
-[UIView animateWithDuration:delay:options:animations:animations:completion:]
来设置其他选项以及动画完成时应执行的代码。Try using block-based animations.
They are cleaner, smoother and are also the current Apple Way to do things. Switching from [UIView beginAnimations:context:] to block-based animations also fixed an animation problem in my code recently.
In your case, a simple block-based animations version would be
[UIView animateWithDuration:1.0f animations:^{[leftWebView setFrame:CGRectMake(0, 0, 384, 916)];}
.You'll probably want to use
-[UIView animateWithDuration:delay:options:animations:animations:completion:]
for setting your other options and the code that should be executed when the animations are finished.