图像序列的反向动画?

时间:2012-11-25 23:11:32

标签: ios xcode

我有一个按钮,我想给它一些动画。一切正常,但我想找到一种方法来反转动画的图像序列顺序,以便按钮似乎恢复它以前的状态。我在文档中找不到任何内容,似乎可能无法反转图像序列? 如果无法撤消订单,我该如何为按钮提供不同的图像序列?我应该用一个新的阵列对它进行收集吗?

da code:

 animatedButton = [[UIImageView alloc] initWithFrame:animButtonRect];
[animatedButton setImage:[UIImage imageNamed:@"messaging_00014.png"]];
[animatedButton setUserInteractionEnabled:YES];

animatedButton.animationImages = [NSArray arrayWithObjects:
                            [UIImage imageNamed:@"mov_00000.png"],
                            [UIImage imageNamed:@"mov_00001.png"],
                            [UIImage imageNamed:@"mov_00002.png"],
                            [UIImage imageNamed:@"mov_00003.png"],
                            [UIImage imageNamed:@"mov_00004.png"],
                            [UIImage imageNamed:@"mov_00005.png"],
                            [UIImage imageNamed:@"mov_00006.png"],
                            [UIImage imageNamed:@"mov_00007.png"],
                            [UIImage imageNamed:@"mov_00008.png"],
                            [UIImage imageNamed:@"mov_00009.png"],
                            [UIImage imageNamed:@"mov_00010.png"],
                            [UIImage imageNamed:@"mov_00011.png"],
                            [UIImage imageNamed:@"mov_00012.png"],
                            [UIImage imageNamed:@"mov_00013.png"],
                            [UIImage imageNamed:@"mov_00014.png"],
 nil];

 animatedButton.animationDuration = 1.0;
 animatedButton.animationRepeatCount = 1;
[self.view addSubview:animatedButton];

1 个答案:

答案 0 :(得分:0)

我知道这个回复有点晚了,但我一直在研究反向动画,并认为我分享了一小段代码。

注意:此代码适用于30张图像的动画序列,图像名称长度为4位。例如。 image_0001.jpg

-(void)animation
{
 NSMutableArray *animationArray = [[NSMutableArray alloc] init];

    int animationSizeTwo = 30;

    for (int i=0; i< animationSizeTwo; i++) {

        NSString *zeros = @"000";

        if ( i >= 1000 ) {

            zeros = @"";

        }
        else if ( i >= 100 ) {

            zeros = @"0";

        }
        else if ( i >= 10 ) {

            zeros = @"00";
        }
        NSString *animationNameTwo = [NSString stringWithFormat:@"(name)"];

        NSString *imageName = [NSString stringWithFormat:@"%@%@%d.jpg", animationNameTwo, zeros, i];

        [animationArrayTwo addObject:[UIImage imageNamed:imageName]];


    }


    _imageView.animationImages = animationArrayTwo;
    _imageView.animationDuration = 1;
    _imageView.animationRepeatCount = 1;
    _imageView.image = [_imageView.animationImages lastObject];
    [_imageView startAnimating];
}

然后,为了反转动画,您只需使用这段代码代替图像计数:

int animationSizeTwo = 0;

    for (int i=30; i> animationSizeTwo; i--) {

正如我所说,回答你的问题可能为时已晚,但将来可能会派上用场, 祝你好运