2013-07-06 2 views
0

Я пытаюсь выполнить эффект взрыва шара, чтобы играть последовательно. Один за другим.Воспроизведение нескольких анимаций в последовательности

То, что я сделал еще:

Для шарового взрывных эффекта я использовал

UIButton *ballButton = (UIButton *)[cell viewWithTag:10]; 

ballButton.imageView.animationImages = [[NSArray alloc] initWithObjects: 
             [UIImage imageNamed:@"1.png"], 
             [UIImage imageNamed:@"2.png"], 
             [UIImage imageNamed:@"3.png"], 
             [UIImage imageNamed:@"4.png"], 
             nil]; 
ballButton.imageView.animationDuration = 1; 
ballButton.imageView.animationRepeatCount = 1; 

и эта линия на код прилагается к нескольким кнопкам в ячейке представления коллекции. Я называю эти ballbutton.imageview запуска анимации, как этот

[UIView animateWithDuration:1 delay:5 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
     NSIndexPath *path2 = [NSIndexPath indexPathForRow:x inSection:0]; 
     UICollectionViewCell *cell = [ballContainer cellForItemAtIndexPath:path2]; 
     UIButton *ballObject = (UIButton *) [cell viewWithTag:10]; 
     [ballObject.imageView startAnimating]; 
    } completion:^(BOOL b){ 
      NSLog(@" here i call next animation of ball blast to execute "); 
}]; 

Я вложенными 3 анимации кнопки, как это.

ответ

0

этот путь я решил мою проблему. сначала я начал анимацию, вызывая этот

 [self startAnim:index]; 

, чем реализовать эту StartAnim, как это и проблема решена.

-(void)StartAnim :(int)x{ 

    NSIndexPath *path2 = [NSIndexPath indexPathForRow:x inSection:0]; 
    UICollectionViewCell *cell = [ballContainer cellForItemAtIndexPath:path2]; 
    UIButton *ballObject = (UIButton *) [cell viewWithTag:10]; 
    [ballObject setBackgroundImage:nil forState:UIControlStateNormal]; 
    ballObject.imageView.image = nil; 
    [ballObject.imageView startAnimating]; 

    double delayInSeconds = 0.15; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 

     if(x-6>=0){ 
      [self StartAnim :(x-6)]; 
     } 
    }); 



} 
0

Прежде всего, почему бы вам не создать одну большую анимацию для всех остальных трех? Вещь с UIView animateWithDuration: заключается в том, что она выполняет блок анимации за период времени, который вы ему дали, то есть установка кадра из (200,200) в (0,0) будет перемещать его пропорционально в течение секунды, в вашем случае , Но свойства UIImageView относительно анимации сделаны таким образом, что анимация уже сделана для вас.

Лично я предложил бы использовать таймер, например:

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:ballObject.imageView.animationDuration 
                target:self 
               selector:@selector(performNextAnimation:) 
               userInfo:nil repeats:NO]; 
[ballObject.imageView startAnimating]; 

И в методе performNextAnimation:

- (void) performNextAnimation{ 
[timer invalidate]; // you have to access the timer you've scheduled with the animation 
timer = nil; 
/* code for starting the next animation */ 
} 
Смежные вопросы