UIImageView animationImages奇怪的行为

时间:2010-11-26 18:35:39

标签: iphone uiimageview

我正在通过NSArray arrayWithObjects填充我的UIImageview的animationImages字段。当我通过UIImage imageNamed将对象放入数组时:UIImageview按预期动画。但是当我通过UIImage分配initWithContentsOfFile中的对象时,我没有看到动画图像(我只看到我传递给UIImageview的initWithImage的默认图像)。有什么想法吗?

干杯!

1 个答案:

答案 0 :(得分:2)

这是因为imageNamed:initWithContentsOfFile:都在不同的目录中。 imageNamed:在您的捆绑目录中查找,initWithContentsOfFile:没有。

如果你有这样的代码:

NSString *file = @"image.png";
UIImage *image = [UIImage imageNamed:file];

但是你想使用initWithContentsOfFile:,你应该使用这段代码:

NSString *file = [[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:file];
相关问题