您不能使用像这样的UIImageView
动画变速。
虽然有几种方法。
1.自己动手。
为此,您可以使用类似NSTimer
的东西,并让它反复激发一种方法来为您更改图像。使用此可以每个时间图像单独地(你甚至可以创建包含的图像和时间的长度来显示它,然后创建与这些阵列的数据对象。
2.操纵当前方法。
如果你有20幅图像,你要告诉他们所有的7秒钟,然后这就是......每幅图像0.35秒。所以5秒的暂停约14图像相当。
因此,而不是将每个图像一次您可以添加1-9一次,然后添加10-14次。11-19一次,然后20-14次。
然后它会像它正在做的那样交换,但是当它达到10时,它会将它交换为同一图像的另一个副本,以便它看起来像暂停。
然后,您必须将持续时间...增加到17秒,以获得每个图像的相似持续时间。
我该怎么办?
虽然它听起来像是一个黑客(因为它),我想我会给第二个方法先去。工作起来要容易得多,所以如果失败了,你还没有花很长时间来完成工作。
第一种方法是设置更多的工作,但会允许更好地控制动画。
快速的方法1
创建一个对象像脏例子...
MyTimedImage
------------
UIImage *image
CGFloat duration
因此,例如...
// probably want this as a property
NSMutableArray *timedImages = [NSMutableArray array];
MyTimedImage *timedImage = [MyTimedImage new];
timedImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"5c_%d.jpg", i]];
timedImage.duration = 0.4;
[timedImages addObject:timedImage];
然后你想办法显示他们...
//set up properties something like this...
@property (nonatomic, assign) NSInteger currentIndex;
@property (nonatomic, assign) BOOL paused;
@property (nonatomic, assign) NSTimer *imageTimer;
- (void)displayNextImage
{
if (self.paused) {
return;
}
NSInteger nextIndex = self.currentIndex + 1;
if (nextIndex == [self.timedImages count]) {
nextIndex = 0;
}
MyTimedImage *nextImage = self.timedImages[nextIndex];
self.currentIndex = nextIndex;
self.imageView.image = nextImage.image;
self.imageTimer = [NSTimer scheduledTimerWithInterval:nextImage.duration target:self selector:@selector(displayNextImage) userInfo:nil repeats:NO];
}
使用您公开的属性可以暂停按钮按下(例如)当前图像上的图像视图。
要启动该过程,只需运行[self displayNextImage];
,您也可以在图像循环中的任意位置启动。
你可以举例说明第一种方法 – user3571918
编辑我的答案。 – Fogmeister