我正在渲染 60 张图像并收到内存警告。下面对我的代码有更好的方法吗?
- (void)change{
for (int aniCount = 1; aniCount < 60; aniCount++) {
if ([UIScreen mainScreen].bounds.size.height == 568) {
self.renderString = [NSString stringWithFormat: @"%i_5.png", aniCount + 1];
self.imageView.image = [UIImage imageNamed:@"1_5.png"];
}else{
self.renderString = [NSString stringWithFormat: @"%i.png", aniCount + 1];
}
// here is the code to pre-render the image
UIImage *frameImage = [UIImage imageNamed:self.renderString];
UIGraphicsBeginImageContext(frameImage.size);
CGRect rect = CGRectMake(0, 0, frameImage.size.width, frameImage.size.height);
[frameImage drawInRect:rect];
UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.menuanimationImages addObject:renderedImage];
}
self.imageView.animationImages = [NSArray arrayWithArray: self.menuanimationImages];
}
这个方法在我的- (void)viewDidLoad
应用程序屏幕的示例:https: //www.youtube.com/watch?v=2f80UcLhOW8