I am working on with a simple animation that I have 10 button and "on click" of one button ( for example 5) all button should start animate one by on but they are animating the same time, please let me know what can be done or ..... Thanks

    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];
        }
    }
}
有帮助吗?

解决方案

As you iterate through your loop, have a variable that holds the desired delay, and add to it at the end of each loop. We'll call this delay.

Now, instead of calling:

[animButton.imageView startAnimating];

Do this:

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

And each button will start animating after the accumulated delay.

其他提示

You need to give some delay time and duration time.

[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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top