#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tom;//tom图片
- (IBAction)eat;//吃小鸟
- (IBAction)fart;//放屁
- (IBAction)drink;//和牛奶
- (IBAction)scratch;//划玻璃
- (IBAction)pie;//扔东西
- (IBAction)cymbal;//敲锣
- (IBAction)knock;//敲头
- (IBAction)left;//左脚
- (IBAction)right;//右脚
- (IBAction)Angry;//生气
- (IBAction)Stomach;//胃口
@end
@implementation ViewController
-(BOOL)prefersStatusBarHidden
{
return YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)initWithdonghua:(NSString *)name andcount:(int)cuont
{
if (self.tom.isAnimating) {
return;
}
NSMutableArray *arrM=[NSMutableArray array];
for (int i=0; i<cuont; i++) {
//全路径没有缓存,自动释放
NSString *filename=[NSString stringWithFormat:@"%@_%02d.jpg",name,i];
NSString *path=[[NSBundle mainBundle]pathForResource:filename ofType:nil];
UIImage *image=[UIImage imageWithContentsOfFile:path];
[arrM addObject:image];
}
self.tom.animationImages=arrM;
self.tom.animationRepeatCount=1;
//播放时间长度
self.tom.animationDuration=arrM.count*0.1;
[self.tom startAnimating];
//类似于定时器,多长时间后执行某个方法
CGFloat delay=self.tom.animationDuration;
[self performSelector:@selector(clearCache) withObject:nil afterDelay:delay];
}
-(void)clearCache
{
self.tom.animationImages=nil;
}
- (IBAction)eat
{
[self initWithdonghua:@"eat" andcount:40];
}
- (IBAction)fart
{
[self initWithdonghua:@"fart" andcount:28];
}
- (IBAction)drink
{
[self initWithdonghua:@"drink" andcount:81];
}
- (IBAction)scratch
{
[self initWithdonghua:@"scratch" andcount:56];
}
- (IBAction)pie
{
[self initWithdonghua:@"pie" andcount:24];
}
- (IBAction)cymbal
{
[self initWithdonghua:@"cymbal" andcount:13];
}
- (IBAction)knock
{
[self initWithdonghua:@"knockout" andcount:81];
}
- (IBAction)left
{
[self initWithdonghua:@"footLeft" andcount:30];
}
- (IBAction)right
{
[self initWithdonghua:@"footRight" andcount:30];
}
- (IBAction)Angry
{
[self initWithdonghua:@"angry" andcount:26];
}
- (IBAction)Stomach
{
[self initWithdonghua:@"stomach" andcount:34];
}
@end
屏幕快照 2016-03-05 05.59.04 PM.png
屏幕快照 2016-03-05 06.04.59 PM.png
屏幕快照 2016-03-05 06.05.53 PM.png
网友评论