我想在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开发的新手
答案 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];