Je sais que vous pouvez effectuer une animation en deux étapes en utilisant des blocs comme:
[UIView animateWithDuration:25.0 delay:0.0 options:UIViewAnimationCurveLinear animations: ^{ aView.alpha = 2.5; } completion:^(BOOL finished) { aView.hidden = YES; } ];
..mais comment pourrais-je créer une animation à plusieurs étages (plus de 2) en utilisant des blocs?
Utiliser des animations nestedes:
[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ //first animation } completion:^(BOOL finished){[UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ //second animation } completion:^(BOOL finished){//and so on.. }];}];
ou vous pouvez créer une méthode d'animation récursive en plusieurs étapes:
-(void) multiStageAnimate{ [UIView animateWithDuration:0.5 delay:0.0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{ //animation code } completion:^(BOOL finished){ if(/* If terminating condition not met*/) [self multiStageAnimate]; }]; }
Je réalise que c'est une question plus ancienne, mais je pensais que j'appendais ma consortingbution.
J'ai créé une class pour gérer l'animation multi-étapes, disponible ici!
Il ne supporte qu'une seule durée et un seul set d'options, mais j'appendai probablement plus de fonctionnalités.
Voici comment vous l'utilisez:
// Create New Animation MSAnimation * newAnimation = [MSAnimation newAnimationWithDuration:0.35 andOptions:UIViewAnimationOptionCurveEaseInOut]; // Add Sequence [newAnimation addNewAnimationStage:^{ greenView.center = CGPointMake(greenView.center.x, greenView.center.y + 100); }]; [newAnimation addNewAnimationStage:^{ greenView.center = CGPointMake(greenView.center.x + 100, greenView.center.y); }]; [newAnimation addNewAnimationStage:^{ greenView.center = CGPointMake(greenView.center.x, greenView.center.y + 100); }]; [newAnimation addNewAnimationStage:^{ greenView.center = CGPointMake(greenView.center.x - 50, greenView.center.y); }]; [newAnimation addNewAnimationStage:^{ greenView.frame = CGRectMake(0, 0, 100, 100); }]; // Animate Your Sequence With Completion [newAnimation animateSequenceWithCompletion:^{ NSLog(@"All finished!"); }];
Vous donne: