Flip image 1, 2, 3 instead of image 1.3 (iPhone SDK)

I use pretty standard code to switch two UIImageViews that are inside a small view. (I am amazed that it worked!)

But what if I had THREE UIImageViews inside a small view ... and wanted to flip between all 3?

I thought I could just cut / paste 2 copies of my code ... but I think not.
When I try to flip 1> 2 .. and then 2> 3 ... it just flips once ... going directly from 1> 3. What happened to 2 ????

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES]; 
[image1 removeFromSuperview];    
[myView addSubview:image2];
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES]; 
[image2 removeFromSuperview];    
[myView addSubview:image3]; 
[UIView commitAnimations];
+3
source share
3 answers

. , . , :

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)contextn {
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES]; 
    [image2 removeFromSuperview];    
    [myView addSubview:image3]; 
    [UIView commitAnimations];
}

:

[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

:

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[image1 removeFromSuperview];    
[myView addSubview:image2];
[UIView commitAnimations];

apple docs

+1

0,5 .

, , , .

0

Jill

In your second block of code, do the following.

[UIView beginAnimations:nil context:NULL];

// This will cause your second animation block to wait 0.5 second, which will be 
// enough time for the second one to kick in and do it thing.
[UIView setAnimationDelay:0.5];

[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES]; 
[image2 removeFromSuperview];    
[myView addSubview:image3]; 
[UIView commitAnimations];
0
source

Source: https://habr.com/ru/post/1732467/


All Articles