- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tag = 100;
// [NSTimer scheduledTimerWithTimeInterval:1/24.0 target:self selector:@selector(changeImage:) userInfo:button repeats:YES];
//使用系统自带的动画效果
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
for (int i=1; i<18; i++) {
NSString *name = [NSString stringWithFormat:@"campFire%02d.gif",i];
UIImage *image = [UIImage imageNamed:name];
[array addObject:image];
}
myImageView.animationImages = array;
myImageView.animationDuration = 1/24.0 * [myImageView.animationImages count];
myImageView.animationRepeatCount = 0;
[myImageView startAnimating];
[NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(stopAnimating) userInfo:nil repeats:YES];
}
- (void)stopAnimating
{
[myImageView stopAnimating];
}
- (void)changeImage:(NSTimer *)timer
{
//userInfo用来传对象
UIButton *button = (UIButton*)timer.userInfo;
NSLog(@"button.tag =%d",button.tag);
static int i=1;
i++;
if (i>17) {
i=1;
}
NSString *stringName = [NSString stringWithFormat:@"campFire%02d.gif",i];
myImageView.image = [UIImage imageNamed:stringName];
}