使い方は簡単でファイル名を渡すだけ。
UIImage* image = [UIImage animatedGIFNamed:@"ajax-loader"];
内部的には GIF内の画像を1枚づつ取り出して UIImage のアニメーションとして構成している。
NSDictionary* properties =
(NSDictionary*)CGImageSourceCopyProperties(source, NULL);
NSDictionary* gifProperties = [properties objectForKey:
(NSString*)kCGImagePropertyGIFDictionary];
[properties release];
size_t count = CGImageSourceGetCount(source);
NSMutableArray* images = [NSMutableArray array];
for (size_t i = 0; i < count; i++) {
CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);
[images addObject:[UIImage imageWithCGImage:image]];
CGImageRelease(image);
}
NSTimeInterval duration = [[gifProperties objectForKey:
(NSString*)kCGImagePropertyGIFDelayTime] doubleValue];
if (!duration) {
duration = (1.0f/10.0f)*count;
}
CFRelease(source);
また -animatedImageByScalingAndCroppingToSize: というメソッドが用意されていて、これを使うと縮小もできる。なかなか便利。
ちょっとしたコードだがウェイトアイコンなどを表示する時に役立ちそう。
関連情報
アイコンジェネレータサイト。サイト上でアニメーション GIFを作ってダウンロードできる。
試しに最初のサイトでアニメーションGIFを作り、LBGIFImageで表示させてみた。
問題なくアニメーション表示できた(静止画だと全然わからないが)。



