//
// ViewController.m
// TomCat
//
// Created by 黄松凯 on 15/2/17.
// Copyright (c) 2015年 SK. All rights reserved.
//
#import “ViewController.h”
@interface ViewController ()
– (IBAction)drink;
– (IBAction)head;
– (IBAction)cymbal;
– (IBAction)fart;
– (IBAction)scratch;
– (IBAction)eat;
– (IBAction)pie;
@property (weak, nonatomic) IBOutlet UIImageView *tom;
@end
@implementation ViewController
– (void)viewDidLoad {
[super viewDidLoad];
}
//将方法进行封装,可以
-(void)runAnimationWithCount:(int)count name:(NSString *)name
{
if(self.tom.isAnimating)//如果正在喝牛奶,则不要打断
return;
//加载所有的动画图片
NSMutableArray *images=[NSMutableArray array];
for(int i=0;i<count;i++)
{
//文件名
NSString *filename=[NSString stringWithFormat:@”%@_%02d.jpg”,name,i];
//加载图片(这种方法有缓存,不利用内存优化)
// UIImage *image=[UIImage imageNamed:filename];
//添加图片到数组中
//[images addObject:image];
NSBundle *bundle=[NSBundle mainBundle];
NSString *path=[bundle pathForResource:filename ofType:nil];
UIImage *image=[UIImage imageWithContentsOfFile:path];
[images addObject:image];
}
self.tom.animationImages=images;
//设置播放次数
self.tom.animationRepeatCount=1;
//设置播放时间
self.tom.animationDuration=2.0;
//开始播放
[self.tom startAnimating];
CGFloat delay=self.tom.animationDuration+1;
[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:delay];
}
– (IBAction)drink
{
[self runAnimationWithCount:81 name:@”drink”];
}
– (IBAction)head {
[self runAnimationWithCount:81 name:@”knockout”];
}
– (IBAction)cymbal {
[self runAnimationWithCount:13 name:@”cymbal”];
}
– (IBAction)fart {
[self runAnimationWithCount:28 name:@”fart”];
}
– (IBAction)scratch {
[self runAnimationWithCount:56 name:@”scratch”];
}
– (IBAction)eat {
[self runAnimationWithCount:40 name:@”eat”];
}
– (IBAction)pie {
[self runAnimationWithCount:24 name:@”pie”];
}
@end
转载于:https://www.cnblogs.com/SKuncle/p/4295347.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/34933.html