我有一个UIPageViewController,它显示5个gif,每页一个。 FLAnimatedImage工作得很好,只有一个缺点,没有设置动画循环,所以我用https://github.com/Flipboard/FLAnimatedImage/pull/60来实现它。
但是gif完成并在一个控制器中停止并且我移动到另一个控制器然后返回到前一个控制器后发生另一个问题,gif将在延迟后启动。
我不确定如何解决这个问题。 FLAnimatedImages类中的所有延迟都与动画延迟有关,而与播放延迟无关。
以下是方法initWithAnimatedGIFData
中FLAnimatedImage.m类的摘录:
// Try to use the unclamped delay time; fall back to the normal delay time.
NSNumber *delayTime = [framePropertiesGIF objectForKey:(id)kCGImagePropertyGIFUnclampedDelayTime];
if (!delayTime) {
delayTime = [framePropertiesGIF objectForKey:(id)kCGImagePropertyGIFDelayTime];
}
// If we don't get a delay time from the properties, fall back to `kDelayTimeIntervalDefault` or carry over the preceding frame's value.
const NSTimeInterval kDelayTimeIntervalDefault = 0.1;
if (!delayTime) {
if (i == 0) {
FLLogInfo(@"Falling back to default delay time for first frame %@ because none found in GIF properties %@", frameImage, frameProperties);
delayTime = @(kDelayTimeIntervalDefault);
} else {
FLLogInfo(@"Falling back to preceding delay time for frame %zu %@ because none found in GIF properties %@", i, frameImage, frameProperties);
delayTime = delayTimesMutable[i - 1];
}
}
// Support frame delays as low as `kDelayTimeIntervalMinimum`, with anything below being rounded up to `kDelayTimeIntervalDefault` for legacy compatibility.
// This is how the fastest browsers do it as per 2012: http://nullsleep.tumblr.com/post/16524517190/animated-gif-minimum-frame-delay-browser-compatibility
const NSTimeInterval kDelayTimeIntervalMinimum = 0.02;
// To support the minimum even when rounding errors occur, use an epsilon when comparing. We downcast to float because that's what we get for delayTime from ImageIO.
if ([delayTime floatValue] < ((float)kDelayTimeIntervalMinimum - FLT_EPSILON)) {
FLLogInfo(@"Rounding frame %zu's `delayTime` from %f up to default %f (minimum supported: %f).", i, [delayTime floatValue], kDelayTimeIntervalDefault, kDelayTimeIntervalMinimum);
delayTime = @(kDelayTimeIntervalDefault);
}
delayTimesMutable[i] = delayTime;
} else {
FLLogInfo(@"Dropping frame %zu because valid `CGImageRef` %@ did result in `nil`-`UIImage`.", i, frameImageRef);
}
CFRelease(frameImageRef);
} else {
FLLogInfo(@"Dropping frame %zu because failed to `CGImageSourceCreateImageAtIndex` with image source %@", i, _imageSource);
}
}
_delayTimes = [delayTimesMutable copy];
_frameCount = [_delayTimes count];
答案 0 :(得分:0)
作为变通方法的解决方案是将UIPageController过渡样式更改为curl而不是滚动,因此将始终创建页面内容控制器的新实例,并且将始终将gif重新加载到内存中。