使用物理c为iphone预加载UIImageView动画 [英] Preloading a UIImageView animation using objective c for the iphone

查看:83
本文介绍了使用物理c为iphone预加载UIImageView动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很棒的动画图像。它由180个高质量的图像组成,并且可以很好地连续播放。我的问题是,第一次加载包含这些图像的视图时,需要很长时间才能加载。之后的每一次都会立即加载,因为我假设图像已被缓存或预加载!我来自闪光背景,因为我确信你知道预装载器和muck一样普遍,所以我觉得这不应该很难找到但是经过无数的谷歌搜索后我找不到任何关于预装的好例子或任何关于为什么存在的文章延迟以及如何处理它。

I have an animated image which works great. It consists of 180 high quality images and it plays fine and loops continuously. My problem is that the first time I load the view containing these images it takes a long time to load. Every subsequent time after that it loads immediately as I am assuming that the images have been cached or preloaded!!! I come from a flash background and as I am sure you aware preloaders are as common as muck so I don't feel this should be difficult to find but after countless googling I cannot find any good examples on preloading or any articles on why there is a delay and what to do about it.

所以我的问题是:


  1. 是info.plist中有一个复选框,可以在应用程序开始时预加载我的所有图像吗?

  1. Is there a checkbox in the info.plist to preload all my images at the start of the app?

如何预加载图像,是否有任何简单的示例项目我可以看一下吗?

How can you preload images and are there any simple example projects that I could look at?

这是实现本质上视频但输出到png序列的最佳方法吗?

Is this the best way to implement what is essentially a video but has been output to a png sequence?

是否存在另一种方法,因为viewDidLoad不能像我期望的那样工作。它跟踪完成的加载图像(参见下面的代码),但视图在加载图像后没有显示一两秒,所以如果视图在图像加载之前没有显示,那么UIActivityIndi​​catorView也不会显示相同的观点。

Is there another method as viewDidLoad does not work as I expect it to do. It traces "FINISHED LOADING IMAGES" (see code below) but the view does not show for a second or two after the images have been loaded so if the view does not show until the images have loaded then neither will the UIActivityIndicatorView which is also in the same view.

你如何在目标c中听事件?

How do you do event listening in objective c?

以下是viewDidLoad中的代码,我认为这是相当标准的:

任何帮助都非常感谢,因为我正在敲打我的头在砖墙上看起来在ui开发中看起来非常基本。帮助:)

Any help is greatly appreciated as I am banging my head on a brick wall on something that seems so basic in ui development. Help :)

- (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");

} 

干杯

M

推荐答案

如果有人发现这个问题,我有一个答案,即预渲染图像像这样。

In case someone finds this question, I have an answer, which is to pre-render the images like this.

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;

我已尝试过多种其他方法预加载图片,这是我唯一的事情。发现有效。

I have tried multiple other methods of pre-loading images, and this is the only thing I've found that works.

这篇关于使用物理c为iphone预加载UIImageView动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆