Многоступенчатая анимация с использованием блоков - PullRequest
5 голосов
/ 10 августа 2011

Я знаю, что вы можете выполнить двухэтапную анимацию, используя блоки примерно так:

[UIView animateWithDuration:25.0 delay:0.0 options:UIViewAnimationCurveLinear animations:
     ^{ 
         aView.alpha = 2.5;         
     } 
         completion:^(BOOL finished)
     {
         aView.hidden = YES; 
     }
 ];

.. но как бы я создал многоступенчатую (более 2) анимацию с использованием блоков?

Ответы [ 3 ]

11 голосов
/ 10 августа 2011

Использовать вложенные анимации:

[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..
                                                              }];}];
8 голосов
/ 12 августа 2011

или вы можете создать рекурсивный, многоэтапный метод анимации:

-(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];
                 }];
}
0 голосов
/ 19 марта 2014

Я понимаю, что это более старый вопрос, но я подумал, что добавлю свой ввод.

Я создал класс для обработки многоступенчатой ​​анимации, доступно здесь!

В настоящее время поддерживается только одна длительность и набор параметров, но я, вероятно, добавлю больше возможностей.

Вот как вы его используете:

// 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!");
}];

Дает вам:

Animation Demo

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...