您不能使用像這樣的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