我有一个很好的动画图像.它由180个高质量的图像组成,它可以很好地循环播放.我的问题是,第一次加载包含这些图像的视图时,需要很长时间才能加载.之后的每一次都会立即加载,因为我假设图像已被缓存或预加载!我来自闪光背景,因为我确信你知道预装载器和muck一样普遍,所以我觉得这不应该很难找到但是经过无数的谷歌搜索我找不到任何关于预装的好例子或任何关于为什么有的文章延迟以及如何处理它.
所以我的问题是这样的:
info.plist中是否有一个复选框可以在应用程序开头预加载我的所有图像?
你怎么能预装图像,有没有我可以看到的简单示例项目?
这是实现本质上是视频但是已经输出到png序列的最佳方式吗?
还有另一种方法,因为viewDidLoad不能像我期望的那样工作.它跟踪"完成的加载图像"(参见下面的代码),但视图在图像加载后没有显示一两秒,所以如果视图在图像加载之前没有显示,那么UIActivityIndicatorView也不会相同的观点.
你如何在目标c中进行事件倾听?
下面是viewDidLoad中的代码,我认为它是相当标准的:
我非常感激任何帮助,因为我正在敲打砖墙上看起来在ui开发中看起来非常基本的东西.救命 :)
- (void)viewDidLoad {
[super viewDidLoad];
imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];
NSLog(@"START LOADING IMAGES");
// Build array of images, cycling through image names
for (int i = 0; i < IMAGE_COUNT; i++){
[imageArray addObject:[UIImage imageNamed: [NSString stringWithFormat:@"Main_%d.png", i]]];
}
animatedImages = [[UIImageView alloc] initWithFrame:CGRectMake(0,20,IMAGE_WIDTH, IMAGE_HEIGHT)];
animatedImages.animationImages = [NSArray arrayWithArray:imageArray];
animatedImages.animationDuration = 6.0;
animatedImages.animationRepeatCount = 0;
[self.view addSubview:animatedImages];
animatedImages.startAnimating;
[animatedImages release];
NSLog(@"FINISH LOADING IMAGES");
}
Run Code Online (Sandbox Code Playgroud)
干杯
中号
如果有人发现这个问题,我有一个答案,就是像这样预先渲染图像.
NSMutableArray *menuanimationImages = [[NSMutableArray alloc] init];
for (int aniCount = 1; aniCount < 21; aniCount++) {
NSString *fileLocation = [[NSBundle mainBundle] pathForResource: [NSString stringWithFormat: @"bg%i", aniCount + 1] ofType: @"png"];
// here is the code to load and pre-render the image
UIImage *frameImage = [UIImage imageWithContentsOfFile: fileLocation];
UIGraphicsBeginImageContext(frameImage.size);
CGRect rect = CGRectMake(0, 0, frameImage.size.width, frameImage.size.height);
[frameImage drawInRect:rect];
UIImage *renderedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// then add the resulting image to the array
[menuanimationImages addObject:renderedImage];
}
settingsBackground.animationImages = menuanimationImages;
Run Code Online (Sandbox Code Playgroud)
我已经尝试了多种预加载图像的方法,这是我发现的唯一有效的方法.
| 归档时间: |
|
| 查看次数: |
2713 次 |
| 最近记录: |