当我在UIScrollview中使用三个GIF时,应用程序会泄漏更多内存并在某个时刻崩溃。我使用SDWebImage加载GIF。
我的代码:
- (void)setupScrollView:(UIScrollView*)scrMain {
for (int i=0; i < 3; i++) {
UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake((i)*scrMain.frame.size.width + self.view.frame.size.width/2 - (IS_IPHONE_5 ? 215 : (iPhone6 ? 250 : iPhone6Plus ? 360 : 215))/2, self.view.frame.size.height/2 - 355/2, (IS_IPHONE_5 ? 215 : (iPhone6 ? 250 : iPhone6Plus ? 360 : 215)), 355)];
// set scale to fill
imgV.contentMode=UIViewContentModeScaleAspectFit;
// set image
[imgV setImage:[UIImage sd_animatedGIFNamed:[NSString stringWithFormat:@"help%d",i+1]]];
imgV.tag=i+1;
// add to scrollView
[scrMain addSubview:imgV];
}
// set the content size to 4 image width
[scrMain setContentSize:CGSizeMake(scrMain.frame.size.width*3, scrMain.frame.size.height)];
}
如何在没有内存泄漏的情况下加载GIF?
所有解决方案都表示赞赏!!