0

我有这个简单的功能,我对按钮动画进行评分,然后为每个按钮启动动画,但我不知道为什么只有一个按钮动画而不是其他点击的按钮,请帮助我

- (IBAction)startAnimation:(UIButton *)button {

    NSMutableArray* imagesArray = [[NSMutableArray alloc] init];
    for (int images = 0; images < 15; images++) {

        UIImage* buttonImage = [UIImage imageNamed:[NSString stringWithFormat:@"aaqqq00%02d.png", images]];
        [imagesArray addObject:buttonImage];
    }

    NSArray* reversedAnim = [[imagesArray reverseObjectEnumerator] allObjects];

    int buttonTag = button.tag;


    animButton.adjustsImageWhenHighlighted = NO;

    for (int images = 0; images < 15; images++) {

        UIButton *animButton = (UIButton *)[self.view viewWithTag:buttonTag];

        if (images <= buttonTag) {
            animButton.imageView.animationImages = imagesArray;
            [animButton setImage:
             [UIImage imageNamed:@"aaqqq0014.png"] forState:UIControlStateNormal];

        } else {
            animButton.imageView.animationImages = reversedAnim;
            [animButton setImage:
             [UIImage imageNamed:@"aaqqq0000.png"] forState:UIControlStateSelected];

        }
        NSLog(@"%@", animButton.imageView.animationImages);
        animButton.imageView.animationDuration = 1; //whatever you want (in seconds)
        animButton.imageView.animationRepeatCount = 1;
        [animButton.imageView startAnimating];
    }

}
4

1 回答 1

0

您正在传递按钮,因此进行标记查找似乎毫无意义且容易出错(如果层次结构中有多个具有相同标记的视图)。

设置按钮图像视图动画图像 ( animButton.imageView.animationImages) 然后设置单个图像 ( [animButton setImage:...) 也是没有意义的。

你的日志声明对动画图像有什么看法?

于 2013-06-22T09:09:16.027 回答