【问题标题】:UIImage animation not working for all ButtonUIImage 动画不适用于所有按钮
【发布时间】:2013-06-22 06:34:44
【问题描述】:

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

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

}

【问题讨论】:

  • 您确定int buttonTag = button.tag; UIButton *animButton = (UIButton *)[self.view viewWithTag:buttonTag]; 正在返回不同的 个对象吗?

标签: ios animation uibutton uianimation


【解决方案1】:

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

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

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

【讨论】:

  • 好吧,没有图像问题,但突然我发现问题出在 viewWithTag 方法上,该方法需要在循环内
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-06
  • 2012-08-07
  • 2019-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多