------------- ViewController.m -------------
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)drink;
- (IBAction)konckOut;
- (IBAction)footLeft;
@end
@implementation ViewController
- (IBAction)drink
{
[self playAnimationWithImageName:@"drink" andImageCount:81];
}
- (IBAction)konckOut
{
[self playAnimationWithImageName:@"knockout" andImageCount:81];
}
- (IBAction)footLeft
{
[self playAnimationWithImageName:@"footLeft" andImageCount:30];
}
- (void) playAnimationWithImageName:(NSString *) imageName andImageCount:(NSInteger) count
{
if(self.imageView.isAnimating)
{
return;
}
NSMutableArray *images = [NSMutableArray array];
for (int i = 0; i < count; i++)
{
NSString *name = [NSString stringWithFormat:@"%@_%02d",imageName,i];
UIImage *image = [UIImage imageNamed:name];
[images addObject:image];
}
self.imageView.animationImages = images;
self.imageView.animationDuration = 0.05 * count;
self.imageView.animationRepeatCount = 1;
[self.imageView startAnimating];
}
@end