0

我有大约 5,000 个标记为 image_1 到 image_5000 的图像,我如何创建一个循环遍历每个图像然后重复的动画?这是一个 iPhone 应用程序,仅供我个人使用,非常感谢任何帮助。

这是我正在使用的代码,为什么它不起作用。

 //.h
@interface ViewController : UIViewController{
IBOutlet UIImageView *imageView;
int i;
}
@end

 - (void)viewDidLoad
{

i = 0;
[NSTimer scheduledTimerWithTimeInterval:0.5
                                 target:self
                               selector:@selector(loop) 
                               userInfo:nil
                                repeats:YES];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)loop{
if (i<MAX_IMAGES) {

    imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image_%d.bmp",i]];
    NSLog(@"Image:%d",i);
        i+=1;
    if (i >= MAX_IMAGES) {
        i = 1;
    }
  }
}
4

4 回答 4

1

使用自动版本的图像太多,因此您必须使用CADisplayLink自己实现它。在您的显示链接功能中,您应该将图像视图的图像交换到下一个图像。如果你不明白,网上有很多关于如何使用 CADisplayLink 的教程;)。

于 2012-04-16T02:07:01.813 回答
1

Here's an example of the naive approach. You are likely to run into memory issues, but without seeing your image set, it's difficult to know whether it will suffice or not.

UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.view.frame];

NSMutableArray *images = [NSMutableArray arrayWithCapacity:5000];
for(size_t i = 0; i <= 5000; ++i) {
    [images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"image_%d", i]]];
}

imageView.animationImages = images;
imageView.animationDuration = 250.0;
imageView.animationRepeatCount = 0;

[imageView startAnimating];
于 2012-04-16T02:08:25.140 回答
1

I would use a NSTimer to load an image at a time into an UIIMageView. That way you can have controlled of the interval between images changes and minimized memory usage. Let me know if you need sample code.

于 2012-04-16T02:46:16.490 回答
0

You could look at using Cocos2d. Not sure if it can handle 5000 images though.

5000 images sounds a lot like a movie. Have you thought about approaching it from that angle?

于 2012-04-16T07:00:43.207 回答