iOS Tom-猫实现方法

 #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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 今天我们来学一下tom猫的动画吧😊 首先我们先找到一个tom猫的一系列动作。添加到工程中。 class AppDe...
    cyyy520阅读 4,253评论 0 2
  • 精简算法 -(void)tomCatAnimationWithName:(NSString *)name /...
    墨染倾阅读 1,513评论 0 0
  • 一、九宫格1.1 ****方法****1 ****只能创建(****ij****)个对象* 1.2 ****方法*...
    AsaGuo阅读 3,122评论 0 1
  • 1.//按钮函数 - (IBAction)beginAction:(UIButton*)sender { NSLo...
    任梦RM阅读 2,586评论 0 0
  • 版本记录 前言 大家在用非智能机的时候,里面的几个游戏都屈指可数,俄罗斯方框、贪吃蛇、Tom猫等等,这里Tom猫就...
    刀客传奇阅读 4,348评论 3 2

友情链接更多精彩内容