将GIF添加到xcode项目

时间:2015-09-28 07:00:18

标签: ios objective-c xcode

我想在iOS应用中将gif文件包含为静态资源。我正在使用FLAnimatedImage库。我可以从网上加载gif并使用:

显示
FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL         URLWithString:@"http://raphaelschaad.com/static/nyan.gif"]]];
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
imageView.animatedImage = image;
imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
[self.view addSubview:imageView];

我必须从本地资源静态加载GIF,而不是从在线获取它。类似的东西:

NSData dataWithContentsOfFile:LOCAL_FILEPATH 

我无法向图片资源添加gif,但想将图片包含在本地文件中。我怎么做?

PS:我是iOS开发的新手

1 个答案:

答案 0 :(得分:4)

如果你已经知道了你的路径,那么你可以像

一样直接打电话
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
imageView.animatedImage = [UIImage animatedImageNamed:@"yourGifImageName" ]; // it take from assests
imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
[self.view addSubview:imageView];

否则,如果你想从bundle

加载
 NSURL *fileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"youranimated.gif" ofType:nil]];
FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:fileURL]];
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
imageView.animatedImage = image;
imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
[self.view addSubview:imageView];