OC:不會說話的湯姆貓(2014年12月)未添加音頻

來源:互聯網
上載者:User

標籤:

代碼:http://download.csdn.net/detail/ytuzhangziyao/8313977


1.第一種方法

/*

     不會說話的湯姆貓

     1.圖片名放在button的title中,提取出來用sender.currentTitle

     2.每個檔案夾中的圖片個數存在button的tag值中,提取出來用sender.tag

     

     */

- (IBAction)clickBtn:(UIButton *)sender {

    NSMutableArray *ary = [NSMutableArrayarray];

   if (![_tomisAnimating]) {

       return;

    }//判斷上一動畫是否在進行,不進行則執行

    

       int num = sender.tag;

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

            //%02表示佔兩位,左邊空缺時自動補0

           NSString *str = [NSStringstringWithFormat:@"%@_%02i.jpg",sender.currentTitle,i];

           UIImage *image = [UIImageimageNamed:str];

            [aryaddObject:image];

        }

       //序列幀動畫

       _tom.animationImages = ary;

       _tom.animationDuration =0.1*num;

        _tom.animationRepeatCount =1;

        [_tomstartAnimating];

}


2.第二種方法

#pragma mark 播放動畫

-(void)playAnimation:(NSString *)name :(int)count{

   if ([_tomisAnimating]) {

       return;

    }//判斷上一動畫是否在進行

    NSMutableArray *ary = [NSMutableArrayarray];

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

        //%02表示佔兩位,左邊空缺時自動補0

        

        //獲得圖片方法<一>

//        NSString *str = [NSString stringWithFormat:@"%@_%02i.jpg",name,i];

//        UIImage *image = [UIImage imageNamed:str];

        

        //獲得圖片方法<二>  需要用到某些照片再提取出來,不需要時釋放掉,佔用記憶體少

       NSString *str = [NSStringstringWithFormat:@"%@_%02i",name,i];

       NSBundle *bundle = [NSBundlemainBundle];

       NSString *path = [bundlepathForResource:strofType:@"jpg"];

       UIImage *image = [UIImageimageWithContentsOfFile:path];


        [aryaddObject:image];

    }

    //序列幀動畫

    _tom.animationImages = ary;

    _tom.animationDuration =0.1*count;

    _tom.animationRepeatCount =1;

    [_tomstartAnimating];

}



/*筆記

   <1>載入圖片,放在緩衝中(找圖片,先從緩衝找,如果沒有,再從手機中找,載入之後永遠不會自己釋放)

   //有緩衝(無法釋放,參數是檔案名稱)經常用的,佔用記憶體小得圖片

   UIImage *image = [UIImage imageNamed:str];

   <2>無緩衝,載入完會釋放(推薦)(用完會被釋放,參數傳得的全是路徑)佔用記憶體大得,不經常用的

   此方法適用於 工程中圖片非常多,並且圖片的像素很大的工程

   使用該方法添加圖片,不會佔用活躍記憶體,每次調用圖片的時候,都是去工程路徑尋找而不再儲存在活躍記憶體中。

   */



代碼:http://download.csdn.net/detail/ytuzhangziyao/8313977


OC:不會說話的湯姆貓(2014年12月)未添加音頻

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.