这会为 Impactdrawarray 中的 UIImageView 设置动画:
if ( ((impact *) [impactarray objectAtIndex:iv]).animframe == 70){
((UIImageView *) [impactdrawarray objectAtIndex:iv]).image =
[UIImage imageWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"explosionA71"
ofType:@"png"]];
}
if ( ((impact *) [impactarray objectAtIndex:iv]).animframe == 71){
((UIImageView *) [impactdrawarray objectAtIndex:iv]).image =
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"explosionA72"
ofType:@"png"]];
}
什么都没有出现:
NSString *myString2 =
[NSString stringWithFormat:@"A%d",
((impact *) [impactarray objectAtIndex:iv]).animframe;
((UIImageView *) [impactdrawarray objectAtIndex:iv]).image =
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:(@"explosion%d", myString2)
ofType:@"png"]];
我使用 NSString 的参考(示例)
NSString *myString23 = [NSString stringWithFormat:@"$%d", money];
moneylabel.text = myString23;
如何在文件名中使用变量?有没有办法通过索引在资源文件夹中加载图像?像imageByIndex:currentanimationframe
什么?我在 UIImage 文档中没有看到任何内容。
回复评论:
NSString *myString2 = [NSString stringWithFormat:@"A%d", ((impact *) [impactarray objectAtIndex:iv]).animframe];
((UIImageView *) [impactdrawarray objectAtIndex:iv]).image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"explosion%d", myString2] ofType:@"png"]];
和
NSString *imagename = [NSString stringWithFormat:@"A%d", ((impact *) [impactarray objectAtIndex:iv]).animframe];
UIImage *myImage = [UIImage imageNamed:imagename];
((UIImageView *) [impactdrawarray objectAtIndex:iv]).image = myImage;
都编译和运行,但图像不显示。