LoginSignup
26
26

More than 5 years have passed since last update.

iOS FLAnimatedImagegif を使ってgifを再生

Posted at

これを使えば恐ろしく簡単にgifを再生できる。

FLAnimatedImagegif とは?

Flipboardが公開しているライブラリで実際Flipboardのアプリでも使われている。
https://github.com/Flipboard/FLAnimatedImage

実際に使ってみる

cocoapodsでインストール

Podfile
pod 'FLAnimatedImage', '~> 1.0'

使いたいViewControllerに2つのヘッダファイルインポート

ViewController.m
#import "FLAnimatedImage.h"
#import "FLAnimatedImageView.h"

メソッド呼び出し方

プロジェクト内のgifファイル(nyan.gif)を再生させたいとき

ViewController.m
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;

WebのURLから再生したいとき

ViewController
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さん。

26
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
26