简体   繁体   中英

Would like to show a new view after a view animation is finished

I have a animation view. When the animation is finished I would like to show a new view by setting its hidden to false.

I set the hidden to false after the animation block code, but it seems like the animation is being done on a separate thread. The view gets unhidden while the animation block is still playing

// start animation block    
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut ];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:mCards[r] cache:YES];

//   mCards[0].image = [UIImage imageNamed:@"card.png"]; //begin
int id=TarretWheel[r];
mCards[r].image = gCardImages[id]; //end

// Start animtion
[UIView commitAnimations];

// show view
mBackground.hidden=false;

You can (and preferably should, actually), be using the newer block-based animation methods on UIView. Check out the following (it has a completion block which is just what you need):

[UIView animateWithDuration:0.5 animations:^{

} completion:^(BOOL finished) {

}];

Edit: There are other variants with options that you may want in your case.

Also, clarification on why you 'should' be using the block-based methods; from the docs (for beginAnimations:context: ):

Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods to specify your animations instead.

My answer is same as Joe but I would recommend using a different API which allows you with configure block.

[UIView animateWithDuration:2 
                      delay:0.0 
                      options:UIViewAnimationOptionTransitionFlipFromLeft|UIViewAnimationOptionCurveEaseOut | 
                      animations:^{

                         //   mCards[0].image = [UIImage imageNamed:@"card.png"]; //begin
                         int id=TarretWheel[r];
                         mCards[r].image = gCardImages[id]; //end

                 }
                 completion:^(BOOL finished){
                       mBackground.hidden=false;
                 }
 ];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM