码迷,mamicode.com
首页 > 其他好文 > 详细

17.小项目:汤姆猫 版本3.0

时间:2015-08-03 00:49:28      阅读:147      评论:0      收藏: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.jpg",imageName,i];

        NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:nil];

        UIImage *image = [UIImage imageWithContentsOfFile:path];

        [images addObject:image];

    }

    self.imageView.animationImages = images;

    self.imageView.animationDuration = 0.05 * count;

    self.imageView.animationRepeatCount = 1;

    [self.imageView startAnimating];

//  当动画播放完毕需要清除animationImages

    

//  第一种方式:

    [self performSelector:@selector(clearImages) withObject:nil afterDelay:self.imageView.animationDuration];

    

//  第二种方式

//  [self.imageView performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.imageView.animationDuration];

    

//  第三种方式

//  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(self.imageView.animationDuration * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

//        self.imageView.animationImages = nil;

//    });

}

- (void) clearImages

{

    self.imageView.animationImages = nil;

}

@end


17.小项目:汤姆猫 版本3.0

标签:

原文地址:http://www.cnblogs.com/lixiang2015/p/4697126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!