從肯伯恩斯實現,我看到動畫是通過循環處理:
- (void)_startAnimations:(NSArray *)images
{
@autoreleasepool {
for (uint i = 0; i < [images count]; i++) {
self.currentImage = i;
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(_animate:)
object:[NSNumber numberWithInt:self.currentImage]];
[mainQueue addOperations:[NSArray arrayWithObject:operation] waitUntilFinished:YES];
sleep(self.timeTransition);
i = (i == [images count]-1) && isLoop ? -1 : i;
}
}
}
一種方法停止動畫添加一個標誌,像這樣:
for (uint i = 0; i < [images count]; i++) {
if (!animationSuspended) {
self.currentImage = i;
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(_animate:)
object:[NSNumber numberWithInt:self.currentImage]];
[mainQueue addOperations:[NSArray arrayWithObject:operation] waitUntilFinished:YES];
i = (i == [images count]-1) && isLoop ? -1 : i;
}
sleep(self.timeTransition);
}
所以,當你設置的標誌,循環體只執行產生延遲(睡眠),和國家的其他部分保持不變。
希望這會有所幫助。
它不起作用,從另一個視圖控制器返回時動畫已死(直到出現新圖像)。 – 2012-02-11 19:54:27