简体   繁体   English

iOS-如何按顺序显示大量图像

[英]iOS - How to display a large number of images in sequence

I am working on an app that needs to flip through 300 or so images in sequence, with a 2 second delay between images. 我正在开发一个需要按顺序翻转300幅左右的图像,图像之间有2秒延迟的应用程序。

These images are barcodes that are generated on the fly during the display. 这些图像是在显示过程中即时生成的条形码。 They are not stored images. 它们不是存储的图像。

The display is in a navigation controller and I would like the user to be able to click the 'back' button without the app crashing from a selector being sent to an instance that no longer exists. 显示屏位于导航控制器中,我希望用户能够单击“后退”按钮,而不会将应用程序从选择器崩溃到发送到不再存在的实例。

I know that it is possible to animate a UIImageView, but I don't want to create an large array of images because of memory issues. 我知道可以对UIImageView进行动画处理,但是由于内存问题,我不想创建大量图像。

I'd like to do this in a loop where I generate the barcode, display the image, delay 2 seconds, and then repeat with the next image. 我想在一个循环中执行此操作,在该循环中,我将生成条形码,显示图像,延迟2秒,然后对下一张图像重复。

The following code works, but crashes if you click the 'back' button, with a 'message sent to deallocated instance' error. 以下代码有效,但是如果您单击“返回”按钮,并出现“向已取消分配的实例发送消息”错误,则崩溃。

   NSSet *dataSet = [self fetchDataSet];

    for (MyBarCode *data in dataSet) {

        // display barcode in UIImageView
        [self updateBarCodeImage:data ];

        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow: 2.0]];
    }

There doesn't seem to be a way to cancel this timer, or I could do that in viewWillDisapear. 似乎没有办法取消此计时器,或者我可以在viewWillDisapear中做到这一点。

What's the right way to do this? 什么是正确的方法?

Please don't just point me to the animationImages examples. 请不要仅将我指向animationImages示例。 I've already seen all of them and -- again -- I don't want to have to hold all these images in memory during the animation. 我已经看过所有这些图像,而且-再次-我不想在动画过程中将所有这些图像保存在内存中。 If there's a way to generate the images on the fly during animation, now that would be interesting. 如果有一种在动画过程中即时生成图像的方法,那将很有趣。

I think something like this should work: 我认为这样的事情应该起作用:

__weak ViewController *bSelf = self;
NSSet *dataSet = [self fetchDataSet];
dispatch_queue_t myQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul);
dispatch_async(myQueue, ^{
    __strong ViewController *sSelf = bSelf;

    for (BoardingPass *data in dataSet) {
    {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
        [sSelf updateBarCodeImage:data]
        });
    }

});

UPDATED: 更新:

Well I am not sure what exactly you are looking for. 好吧,我不确定您到底在寻找什么。 If you are talking about a simple animation than yes, Cocos 2D would be overkill. 如果您谈论的不是简单的动画,那么Cocos 2D可能会过大。 In that case I suggest doing this tutorial which gave me a lot of ideas on a project I was working on some time back: 在这种情况下,我建议您执行本教程,该教程为我以前从事的项目提供了很多想法:

http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial http://www.raywenderlich.com/2454/how-to-use-uiview-animation-tutorial

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM