DelayTime或UnclampedDelayTime为GIFS

将Gif转换为animationUIImage时,每个帧的延迟都是从属性kCGImagePropertyGIFDelayTimekCGImagePropertyGIFUnclampedDelayTime

像这样:

 NSString *frameKeyPath = [NSString stringWithFormat:@"%@.%@",(NSString*)kCGImagePropertyGIFDictionary,kCGImagePropertyGIFUnclampedDelayTime]; CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source,i,nil); NSDictionary *frameProperties = (__bridge NSDictionary*)cfFrameProperties; NSNumber *delayTimeProp = [frameProperties valueForKeyPath:frameKeyPath]; 

Chrome在这两个例子中都select了正确的一个:

kCGImagePropertyGIFDelayTime = 0.1: http : kCGImagePropertyGIFDelayTime

kCGImagePropertyGIFUnclampedDelayTime = 0.01: http : kCGImagePropertyGIFUnclampedDelayTime

为每个案例select一个会导致其中一个示例图像animation太慢或太快

有没有办法确定使用哪个属性?

谢谢

结束使用webkit的方法,select,unclamped,夹或0.1默认

 + (float)frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source { float frameDuration = 0.1f; CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source,index,nil); NSDictionary *frameProperties = (__bridge NSDictionary*)cfFrameProperties; NSDictionary *gifProperties = frameProperties[(NSString*)kCGImagePropertyGIFDictionary]; NSNumber *delayTimeUnclampedProp = gifProperties[(NSString*)kCGImagePropertyGIFUnclampedDelayTime]; if(delayTimeUnclampedProp) { frameDuration = [delayTimeUnclampedProp floatValue]; } else { NSNumber *delayTimeProp = gifProperties[(NSString*)kCGImagePropertyGIFDelayTime]; if(delayTimeProp) { frameDuration = [delayTimeProp floatValue]; } } // Many annoying ads specify a 0 duration to make an image flash as quickly as possible. // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify // a duration of <= 10 ms. See <rdar://problem/7689300> and <http://webkit.org/b/36082> // for more information. if (frameDuration < 0.011f) frameDuration = 0.100f; CFRelease(cfFrameProperties); return frameDuration; }