汤姆猫实现代码

//

//  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
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值