每个周期后延迟的按钮图像阵列动画

时间:2013-06-26 10:31:35

标签: ios animation uiimage uianimation

我正在处理一个简单的动画,我有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];
        }
    }
}

2 个答案:

答案 0 :(得分:0)

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

现在,而不是打电话:

[animButton.imageView startAnimating];

这样做:

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

每个按钮将在累积的延迟后开始制作动画。

答案 1 :(得分: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.