我想要创建图像动画,我有50张png格式的图像现在我想要设置图像名称...这样的东西但不起作用!
我的图片名称是:iamge_0000 to image_0050
pasheAnimation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"pashe_0000.png"],nil];
[pasheAnimation setAnimationRepeatCount:5];
pasheAnimation.animationDuration = 4;
[pasheAnimation startAnimating];
??!?!?!?
杰森代码[已编辑]:NSMutableArray* myImages = [[[NSMutableArray alloc] initWithCapacity:607] autorelease];
for( int i = 1; i <= 607; i++ ) {
[myImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"p%d.png",i]]];
}
butterflyView.animationImages = myImages;
[butterflyView setAnimationRepeatCount:100];
butterflyView.animationDuration = 0;
[butterflyView startAnimating];
答案 0 :(得分:2)
// There are actually 51 images in this series (0000-0050)
NSMutableArray* myImages = [[[NSMutableArray alloc] initWithCapacity:51] autorelease];
for( int i = 0; i <= 50; i++ ) {
[myImages addObject:[UIImage imageNamed:[NSString stringWithFormat:@"image_%04d.png", i]]?:[NSNull null]];
}
答案 1 :(得分:1)
你实际上有51张图像,从零到五十。
NSMutableArray *myImages = [NSMutableArray arrayWithCapacity:51];
for (NSUInteger idx = 0; idx <= 50; idx++) {
NSString *filename = [NSString stringWithFormat:"image_%04d.png", idx];
UIImage *image = [UIImage imageNamed:filename];
if (image) {
[myImages addObject:image];
}
else {
NSLog(@"Could not add %@", filename); // could also throw exception, if you want
}
}