UIImageView过渡Betwen多个图像 [英] UIImageView Transition Betwen Multiple Images

查看:97
本文介绍了UIImageView过渡Betwen多个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码在短时间内更改UIImageView的图像.如您所见,正在使用的图像存储在数组中.

I am using the below code to change the UIImageView's image after a short duration. The images being used are stored in an array as you can see.

问题是,无论我设置了什么持续时间"或延迟",imageview几乎都会立即更改为数组中的最后一张图像.

The problem is, no matter what 'duration' or 'delay' I set, the imageview changes almost instantly to the last image in the array.

我应该使用主线程在每次图像转换之间添加延迟吗?

Should I instead be using the main thread to add a delay between each image transition?

////////////////////////////////////////////////////////////////

 animationCount = 0;
 imageArray =[NSMutableArray new];
 [imageArray addObject:[UIImage imageNamed:@"gauge1final.png"]];
 [imageArray addObject:[UIImage imageNamed:@"gauge2final.png"]];
 [imageArray addObject:[UIImage imageNamed:@"gauge3final.png"]];
 [imageArray addObject:[UIImage imageNamed:@"gauge4final.png"]];
 [imageArray addObject:[UIImage imageNamed:@"gauge5final.png"]];
 [self multiStageAnimate];

////////////////////////////////////////////////////////////////

-(void) multiStageAnimate{
[UIView animateWithDuration:5.0
                      delay:5.0
                    options:UIViewAnimationOptionTransitionCrossDissolve
                 animations:^
                 {
                     self.gauge.image = [imageArray objectAtIndex:animationCount];
                 }
                 completion:^(BOOL finished){

                     animationCount ++;

                     if(animationCount < imageArray.count){
                         [self multiStageAnimate];
                     }
                     else
                     {
                         animationCount = 0;
                     }
                 }];
}

推荐答案

UIImageView 确实具有满足您需求的机制.

UIImageView does have a mechanism to accomplish your need.

UIImageView *imageView = [[UIImageView alloc] init];
imageView.animationImages = [NSArray arrayWithObjects:
                                           [UIImage imageNamed:@"image1"],
                                           [UIImage imageNamed:@"image2"],
                                           [UIImage imageNamed:@"image3"], nil];
imageView.animationRepeatCount = 0; // 0 means repeat without stop.
imageView.animationDuration = 1.5; // Animation duration

[imageView startAnimating];

这篇关于UIImageView过渡Betwen多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆