2013-07-06 103 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 */ 
}