您的位置:首页 > 编程语言

汤姆猫实现代码

2015-08-20 18:59 337 查看
//

//  ViewController.m

//  Tom

//

//  Created by administrator on 15/8/4.

//  Copyright (c) 2015年 gengcong. All rights reserved.

//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *tom;

- (IBAction)drinkClick:(id)sender;

- (IBAction)peiClick:(id)sender;

- (IBAction)eatClick:(id)sender;

- (IBAction)cymbalClick:(id)sender;

- (IBAction)scratchClick:(id)sender;

- (IBAction)fart:(id)sender;

- (IBAction)stomach:(id)sender;

- (IBAction)footleft:(id)sender;

- (IBAction)footright:(id)sender;

- (IBAction)knockoutClick:(id)sender;

- (IBAction)angryClick:(id)sender;

@end

@implementation ViewController

- (IBAction)drinkClick:(id)sender {

[self runAnimationWithName:@"drink" andcount:81];

}

- (IBAction)peiClick:(id)sender {

[self runAnimationWithName:@"pie" andcount:24];

}

- (IBAction)eatClick:(id)sender {

[self runAnimationWithName:@"eat" andcount:40];

}

- (IBAction)cymbalClick:(id)sender {

[self runAnimationWithName:@"cymbal" andcount:13];

}

- (IBAction)scratchClick:(id)sender {

[self runAnimationWithName:@"scratch" andcount:56];

}

- (IBAction)fart:(id)sender {

[self runAnimationWithName:@"fart" andcount:28];

}

- (IBAction)stomach:(id)sender {

[self runAnimationWithName:@"stomach" andcount:34];

}

- (IBAction)footleft:(id)sender {

[self runAnimationWithName:@"footRight" andcount:30];

}

- (IBAction)footright:(id)sender {

[self runAnimationWithName:@"footLeft" andcount:30];

}

- (IBAction)knockoutClick:(id)sender {

[self runAnimationWithName:@"knockout" andcount:81];

}

- (IBAction)angryClick:(id)sender {

[self runAnimationWithName:@"angry" andcount:26];

}

-(void)runAnimationWithName:(NSString*)name andcount:(int)counts

{

if (self.tom.isAnimating) return;

NSMutableArray *images=[[NSMutableArray alloc]init];

for (int i=0; i<counts; i++) {

NSString *thanten=[[NSString alloc]init];

if (i<10){

thanten=[NSString stringWithFormat:@"0%d",i];

}

else{

thanten=[NSString stringWithFormat:@"%d",i];

}

NSString *filename=[NSString stringWithFormat:@"%@_%@.jpg",name,thanten];

UIImage *image=[UIImage imageNamed:filename ];

[images addObject:image];

}

//    设置动画的图片来源

self.tom.animationImages=images;

//   设置播放次数

self.tom.animationRepeatCount=1;

//设置动画播放的时间

self.tom.animationDuration=images.count*0.07;

[self.tom startAnimating];

//设置延时清除内存

CGFloat delay=self.tom.animationDuration +1.0;

[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:delay];

}

//-(void)clean

//{

//    self.tom.animationImages=nil;

//    //[self.tom setAnimationImages:nil];

//

//}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: