简体   繁体   English

UIImageView animationImages奇怪的行为

[英]UIImageView animationImages strange behavior

I'm populating the animationImages field of my UIImageview via NSArray arrayWithObjects. 我正在通过NSArray arrayWithObjects填充我的UIImageview的animationImages字段。 When I put objects in the array via UIImage imageNamed: the UIImageview animates as expected. 当我通过UIImage imageNamed将对象放在数组中时:UIImageview会按预期进行动画处理。 However when I put objects in the array via UIImage alloc initWithContentsOfFile I don't see the animated images (I just see the default image I pass to initWithImage for the UIImageview). 但是,当我通过UIImage alloc initWithContentsOfFile将对象放入数组时,我看不到动画图像(我只是看到传递给UIImageview的initWithImage的默认图像)。 Any ideas? 有任何想法吗?

Cheers! 干杯!

That is because imageNamed: and initWithContentsOfFile: both look in different directories. 那是因为imageNamed:initWithContentsOfFile:都在不同的目录中查找。 imageNamed: looks in your bundle directory, initWithContentsOfFile: does not. imageNamed:在你的bundle目录中查找, initWithContentsOfFile:没有。

If you have code like this: 如果您有这样的代码:

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

But you want to use initWithContentsOfFile: , you should use this code: 但是你想使用initWithContentsOfFile: ,你应该使用这段代码:

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

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

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