我在我的应用中使用了一些非常大的图像。它们的分辨率很大,所以它在iPhone 6+上看起来不错。图像大小约为3.5MB。
当我在iphone上运行应用程序并使用[UIImage imageNamed:@"foo.png"]
在单元格中加载图像时;如果我滚动所有10个单元格,它会将内存填充到100MB。
我查看了仪器,它向我显示每个图像都是9MB大。这是正常的吗?
这是我的UICollectionViewCell代码,我必须告诉你,单元格正在加载正常,当时只有一个,所以单元格没有任何问题。
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
WallpaperCell *cell = (WallpaperCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"wallpaperCellIdentifier" forIndexPath:indexPath];
cell.contentView.frame = cell.bounds;
cell.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
NSString *imageName = [self.wallpapers objectAtIndex:indexPath.row];
UIImage *image = [UIImage imageNamed:imageName];
[cell setWallpaperImage:image];
[cell setWallpaperName:imageName];
NSLog(@"cell:%@",cell);
return cell;
}
答案 0 :(得分:0)
要将图像绘制到屏幕上,UIImage需要是一个没有压缩的位图。您的png采用压缩格式,因此比位图表示要小得多。