2017-04-24 44 views
0

在我的项目中,我实现了一个视图,其中包含一些从API加载的gif。所有都分组在一个集合视图中。我在这里有一个问题,应用程序意外退出,在调试器中,我得到了像“因内存问题而终止”这样的暗示。在集合视图中处理n个gif Swift

所以请帮助我解决这个问题。如果第三方库可用于处理此问题也将罚款。

在此先感谢。

+0

可以用客观的C库,所以我可以给你? – KKRocks

+0

从调试消息中可以清楚地看到内存不足。 – lukya

回答

2

尝试这个库:https://github.com/onevcat/Kingfisher。它支持GIF。 你可以简单地在你的cellForItem方法设置链接到你的GIF,这LIB将处理其余部分(包括下载和缓存文件):

let url = URL(string: "Your-Gif-URL") 
cell.imageView.kf.setImage(with: url) 
+0

谢谢,工作。 –

1

尝试为避免内存警告这一目标的C库。

https://github.com/yfme/UIImageView-PlayGIF

示例代码段

 YFGIFImageView *launcherImageView =[[YFGIFImageView alloc]initWithFrame:[[UIScreen mainScreen] bounds]]; 
     launcherImageView.gifPath = [[NSBundle mainBundle] pathForResource:@"matis.gif" ofType:nil];; 
     launcherImageView.unRepeat = YES; 

     launcherImageView.clipsToBounds = YES; 
     [self.window addSubview:launcherImageView]; 
     [launcherImageView startGIF]; 
相关问题