iOS Tom-貓實(shí)現(xiàn)方法

 #import "ViewController.h"

 @interface ViewController ()
 @property (weak, nonatomic) IBOutlet UIImageView *tom;//tom圖片

 - (IBAction)eat;//吃小鳥
 - (IBAction)fart;//放屁
 - (IBAction)drink;//和牛奶
 - (IBAction)scratch;//劃玻璃
 - (IBAction)pie;//扔?xùn)|西
 - (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++) {
    //全路徑?jīng)]有緩存,自動釋放
    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];
//類似于定時器,多長時間后執(zhí)行某個方法
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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 今天我們來學(xué)一下tom貓的動畫吧?? 首先我們先找到一個tom貓的一系列動作。添加到工程中。 class AppDe...
    cyyy520閱讀 881評論 0 2
  • 精簡算法 -(void)tomCatAnimationWithName:(NSString *)name /...
    墨染傾閱讀 221評論 0 0
  • 一、九宮格1.1 ****方法****1 ****只能創(chuàng)建(****ij****)個對象* 1.2 ****方法*...
    AsaGuo閱讀 482評論 0 1
  • 1.//按鈕函數(shù) - (IBAction)beginAction:(UIButton*)sender { NSLo...
    任夢RM閱讀 348評論 0 0
  • 版本記錄 前言 大家在用非智能機(jī)的時候,里面的幾個游戲都屈指可數(shù),俄羅斯方框、貪吃蛇、Tom貓等等,這里Tom貓就...
    刀客傳奇閱讀 1,002評論 3 2

友情鏈接更多精彩內(nèi)容