16.小项目:汤姆猫 版本2.0

-------------  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

 

posted @ 2015-08-02 22:51  我要选李白  阅读(160)  评论(0编辑  收藏  举报