Ios4 iOS 4.2:使用块动画翻转图像
我在我的应用程序中有一段代码:Ios4 iOS 4.2:使用块动画翻转图像,ios4,core-animation,Ios4,Core Animation,我在我的应用程序中有一段代码: [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:imgView cache:YES]; imgView.image = img2; [UIView commitAnimations]; 但在iOS 4
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:imgView cache:YES];
imgView.image = img2;
[UIView commitAnimations];
但在iOS 4.0及更高版本中不鼓励使用这种方法,我应该使用transitionWithView:duration:options:animations:completion:
我不能让它正常工作。有人能帮我吗?
谢谢 我根据您的代码创建了此函数:
- (void)flipCurrentView:(UIView*)oldView withNewView:(UIView*)newView reverse:(BOOL)reverse
{
newView.alpha = 0;
[UIView transitionWithView:newView
duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
oldView.alpha = 0;
newView.alpha = 1;
}
completion:^(BOOL finished){
if(reverse){
[self flipCurrentView:newView withNewView:oldView reverse:NO];
}
finished = YES;
}];
}
谢谢!就像一个符咒。@KennyTM:你能用它来澄清吗?
- (void)flipCurrentView:(UIView*)oldView withNewView:(UIView*)newView reverse:(BOOL)reverse
{
newView.alpha = 0;
[UIView transitionWithView:newView
duration:1
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
oldView.alpha = 0;
newView.alpha = 1;
}
completion:^(BOOL finished){
if(reverse){
[self flipCurrentView:newView withNewView:oldView reverse:NO];
}
finished = YES;
}];
}