0

I have this simple function where i sap rate the button animation and then start animation for every button but i dont know why only one button animate not others which clicked, please help me with this

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

}
Retro
  • 3,985
  • 2
  • 17
  • 41
  • Are you sure `int buttonTag = button.tag; UIButton *animButton = (UIButton *)[self.view viewWithTag:buttonTag];` is returning *different* objects? – maroux Jun 22 '13 at 07:51

1 Answers1

0

You're passing the button, so doing the tag lookup seem pointless and error prone (if there are multiple views with the same tag in the hierarchy).

Setting the buttons image view animation images (animButton.imageView.animationImages) and then after that setting a single image ([animButton setImage:...) is also pointless.

What does your log statement say about the animation images?

Wain
  • 118,658
  • 15
  • 128
  • 151
  • well there is no images issue but suddenly i found the problem was with viewWithTag method which need to be inside of loop – Retro Jun 22 '13 at 13:14