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