gpt4 book ai didi

iPhone : How to manage 130 images in ImageView?

转载 作者:行者123 更新时间:2023-12-01 18:01:45 25 4
gpt4 key购买 nike

我有超过 100 张图像,我使用以下代码在 imageView 中加载:

   [imgV setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@%d.png",prefixName,counter]]];

上面的代码将每 0.03 秒调用一次, counter是加载不同图像的数字。

上面的想法给了我动画效果,它用来在 0.03s 上加载不同的图像。

但是当图像更多时,它会使用 crash .

我该怎么办 ?或者我如何在我的情况下保持内存?任何的想法?

最佳答案

尝试使用

NSString *fileLocation = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];
[UIImage imageWithData:imageData];

代替
[imgV setImage:[UIImage imageNamed:fileName.extension]];

UIImageView 也有 setAnimationImages 方法
imgView=[[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
[imgView setAnimationImages:myArray];//myArray - array of Images
[imgView setAnimationDuration:1];
[imgView setAnimationRepeatCount=0];
[imgView startAnimating];
[self addSubview:imgView];

关于iPhone : How to manage 130 images in ImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8615687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com