我在我的项目上创建了动画,它在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];
//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];
谢谢!
答案 0 :(得分:1)
尝试使用基于块的动画。
它们更干净,更流畅,也是目前Apple的做事方式。从[UIView beginAnimations:context:]切换到基于块的动画也最近修复了我的代码中的动画问题。
在您的情况下,一个简单的基于块的动画版本将是[UIView animateWithDuration:1.0f animations:^{[leftWebView setFrame:CGRectMake(0, 0, 384, 916)];}
。
您可能希望使用-[UIView animateWithDuration:delay:options:animations:animations:completion:]
来设置其他选项以及动画完成时应执行的代码。