3

我正在处理一个简单的动画,我有 10 个按钮和一个按钮的“单击”(例如 5 个)所有按钮都应该开始一个动画,但它们同时动画,请让我知道可以做什么或.....谢谢

    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;

for (int images = 1; images <= 10; images++) {
    UIButton *animButton = (UIButton *)[self.view viewWithTag:images];
    if (images <= buttonTag) {
        animButton.imageView.animationImages = imagesArray;
        [animButton setImage:
         [UIImage imageNamed:@"aaqqq0014.png"] forState:UIControlStateNormal];
        animButton.adjustsImageWhenHighlighted = NO;
        animButton.imageView.animationDuration = 1; //whatever you want (in seconds)
        animButton.imageView.animationRepeatCount = 1;
        [animButton.imageView startAnimating];
    } else {

        if (currentButtonTag_ >= images) {
            animButton.imageView.animationImages = reversedAnim;
            [animButton setImage:
             [UIImage imageNamed:@"aaqqq0000.png"] forState:UIControlStateNormal];
            animButton.adjustsImageWhenHighlighted = NO;
            animButton.imageView.animationDuration = 0.2; //whatever you want (in seconds)
            animButton.imageView.animationRepeatCount = 1;
            [animButton.imageView startAnimating];
        }
    }
}
4

2 回答 2

0

你需要给一些延迟时间和持续时间。

[UIView animateWithDuration:0.6
                          delay:2.0
                        options: UIViewAnimationCurveEaseOut
                     animations:^{S1Button.frame = CGRectMake(20, 10, 50, 10);S1buttonA.alpha = 0;}
                     completion:nil];

Set this for every animation.

于 2013-06-26T10:52:26.130 回答
0

当您遍历循环时,有一个变量来保存所需的延迟,并在每个循环结束时添加到它。我们称之为delay.

现在,而不是调用:

[animButton.imageView startAnimating];

做这个:

[animButton.imageView performSelector:@selector(startAnimating) withObject:nil afterDelay:delay];

并且每个按钮将在累积延迟后开始动画。

于 2013-06-26T10:36:41.283 回答