iOS cocoapods FLAnimatedImagegif を使ってgifを再生
FLAnimatedImagegifを使用(あのFlipboardが公開してるライブラリ)
■ Podでインストール
pod 'FLAnimatedImage', '~> 1.0'
■ 使いたいViewControllerに2つのヘッダファイルインポート
#import "FLAnimatedImage.h" #import "FLAnimatedImageView.h"
ローカルのgifファイル(nyan.gif)を再生させたいとき
NSURL *gifUrl = [[NSBundle mainBundle] URLForResource:@"nyan" withExtension:@"gif"]; FLAnimatedImage *gifImage = [[FLAnimatedImage alloc] initWithAnimatedGIFData:[NSData dataWithContentsOfURL:gifUrl]]; FLAnimatedImageView *animationView = [[FLAnimatedImageView alloc] init]; animationView.animatedImage = gifImage; self.view = animationView;
ウェブのURLにあるgifを再生させたいとき
FLAnimatedImage *gifImage = [[FLAnimatedImage alloc] initWithAnimatedGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://raphaelschaad.com/static/nyan.gif"]]]; FLAnimatedImageView *animationView = [[FLAnimatedImageView alloc] init]; animationView.animatedImage = gifImage; self.view = animationView;
たったこれだけでできる。ありがとうFlipboardさん。