Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios4 iOS 4.2:使用块动画翻转图像_Ios4_Core Animation - Fatal编程技术网

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;
                    }];   
}