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 个动画按钮。

4

2 回答 2

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



}
于 2013-07-11T04:22:03.547 回答
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 */
}
于 2013-07-07T09:41:50.190 回答