标签:style blog io ar color os 使用 sp for
1 self.tom.animationImages = images; // 存储了多张组成动画的图片 2 3 [self.tom setAnimationRepeatCount:1]; // 默认0是无限次 4 [self.tom setAnimationDuration: images.count/FramesCount]; 5 [self.tom startAnimating];
1 // imageNamed: 有缓存 2 // UIImage *image = [UIImage imageNamed:fileName]; 3 4 // imageWithContentOfFile: 没有缓存(传入文件的全路径) 5 NSBundle *bundle = [NSBundle mainBundle]; 6 NSString *path = [bundle pathForResource:fileName ofType:nil]; 7 UIImage *image = [UIImage imageWithContentsOfFile:path];
[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration + 1];
1 #import "ViewController.h" 2 3 #define FramesCount 24 // 动画帧数/秒 4 5 @interface ViewController () 6 @property (weak, nonatomic) IBOutlet UIImageView *tom; 7 8 - (IBAction)drink; 9 - (IBAction)knockHead; 10 11 @end 12 13 @implementation ViewController 14 15 - (void)viewDidLoad { 16 [super viewDidLoad]; 17 // Do any additional setup after loading the view, typically from a nib. 18 19 } 20 21 - (void)didReceiveMemoryWarning { 22 [super didReceiveMemoryWarning]; 23 // Dispose of any resources that can be recreated. 24 } 25 26 /** 点击牛奶按钮 */ 27 - (IBAction)drink { 28 [self runAnimationWithName:@"drink" andCount:80]; 29 } 30 31 /** 点击头部 */ 32 // 实质是在头部放置了一个不带文字的透明按钮 33 - (IBAction)knockHead { 34 [self runAnimationWithName:@"knockout" andCount:80]; 35 } 36 37 /** 运行相应动画 */ 38 - (void) runAnimationWithName:(NSString *) animationName andCount:(int) count { 39 if (self.tom.isAnimating) return; 40 41 NSMutableArray *images = [NSMutableArray array]; 42 for (int i=0; i <= count; i++) { 43 NSString *fileName = [NSString stringWithFormat:@"%@_%02d.jpg", animationName, i]; 44 45 // imageNamed: 有缓存 46 // UIImage *image = [UIImage imageNamed:fileName]; 47 48 // imageWithContentOfFile: 没有缓存(传入文件的全路径) 49 NSBundle *bundle = [NSBundle mainBundle]; 50 NSString *path = [bundle pathForResource:fileName ofType:nil]; 51 UIImage *image = [UIImage imageWithContentsOfFile:path]; 52 53 [images addObject:image]; 54 } 55 56 self.tom.animationImages = images; // 存储了多张组成动画的图片 57 58 [self.tom setAnimationRepeatCount:1]; // 默认0是无限次 59 [self.tom setAnimationDuration: images.count/FramesCount]; 60 [self.tom startAnimating]; 61 62 [self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration + 1]; 63 } 64 65 66 @end
标签:style blog io ar color os 使用 sp for
原文地址:http://www.cnblogs.com/hellovoidworld/p/4119737.html