国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

[iOS基礎控件-3.4]湯姆貓

2019-11-14 19:50:19
字體:
來源:轉載
供稿:網友
需求:
1.點擊按鈕播放相應動畫
2.點擊湯姆貓身體部分(頭、腳、尾巴)顯示動畫
3.當前正在播放動畫不可觸發其他動畫
4.優化緩存、內存管理
 
Image
 
A.序列幀動畫
#1. png格式的文件可以不帶擴展名訪問,而且可以放到”Images.scassets”的組中預覽,jpg只能放到support file中了,而且訪問的時候要寫上擴展名
#2. 在ViewController中的屬性欄可以設置storyboard模型的大小
 
#3. 拖入文件夾的時候要選擇“Create Groups"才能正確引用,不要選擇”Create Folder References"
     1.Create groups for any added folders:把選擇的文件添加到工程的group下,如果你選擇的是文件,則把文件夾認為是group。他添加的文件夾對應的工程目錄和文件路徑不一定是一一對應的。你可以刪除文件,可以把這個文件刪除在工程外,也可以刪除文件對應的本地文件。應該它生成的文件夾是黃色的。
     2.Create folder references for any added folders:這種方法是建立一個文件夾的索引,同時文件夾中的所有文件也會添加到整個工程。他添加的文件夾對應的工程目錄和文件路徑是一一對應的。你要刪除其中的文件的話可以直接到文件目錄下把文件刪除,然后再刷新一下目錄,文件就會被刪除了。這樣添加文件夾的方法很方便,你在做cocos2d的工程時應該會經常用到。應該他生成的文件夾是藍色的
 
#4. 整型占位符的0填充:  %02d代表兩位整型,高位不滿的用0填充
 
1.動畫執行方法
1     self.tom.animationImages = images; // 存儲了多張組成動畫的圖片23     [self.tom setAnimationRepeatCount:1]; // 默認0是無限次4     [self.tom setAnimationDuration: images.count/FramesCount];5     [self.tom startAnimating];
 
2.圖片緩存機制&釋放內存
a.使用          UIImage *image = [UIImage imageNamed:fileName];
會存儲圖片到混存,加載大量圖片的時候會消耗大量內存
1         // imageNamed: 有緩存2 //        UIImage *image = [UIImage imageNamed:fileName];34         // imageWithContentOfFile: 沒有緩存(傳入文件的全路徑)5         NSBundle *bundle = [NSBundle mainBundle];6         NSString *path = [bundle pathForResource:fileName ofType:nil];7         UIImage *image = [UIImage imageWithContentsOfFile:path];
 
b.釋放圖片內存
    [self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration + 1];
 
 
B.湯姆貓主要代碼 (使用storyboard拖曳控件方式)
 
 1 #import "ViewController.h" 2 3 #define FramesCount 24 // 動畫幀數/秒 4 5 @interface ViewController () 6 @PRoperty (weak, nonatomic) IBOutlet UIImageView *tom; 7 8 - (IBAction)drink; 9 - (IBAction)knockHead;1011 @end1213 @implementation ViewController1415 - (void)viewDidLoad {16     [super viewDidLoad];17     // Do any additional setup after loading the view, typically from a nib.1819 }2021 - (void)didReceiveMemoryWarning {22     [super didReceiveMemoryWarning];23     // Dispose of any resources that can be recreated.24 }2526 /** 點擊牛奶按鈕 */27 - (IBAction)drink {28     [self runAnimationWithName:@"drink" andCount:80];29 }3031 /** 點擊頭部 */32 // 實質是在頭部放置了一個不帶文字的透明按鈕33 - (IBAction)knockHead {34     [self runAnimationWithName:@"knockout" andCount:80];35 }3637 /** 運行相應動畫 */38 - (void) runAnimationWithName:(NSString *) animationName andCount:(int) count {39     if (self.tom.isAnimating) return;4041     NSMutableArray *images = [NSMutableArray array];42     for (int i=0; i <= count; i++) {43         NSString *fileName = [NSString stringWithFormat:@"%@_%02d.jpg", animationName, i];4445         // imageNamed: 有緩存46 //        UIImage *image = [UIImage imageNamed:fileName];4748         // imageWithContentOfFile: 沒有緩存(傳入文件的全路徑)49         NSBundle *bundle = [NSBundle mainBundle];50         NSString *path = [bundle pathForResource:fileName ofType:nil];51         UIImage *image = [UIImage imageWithContentsOfFile:path];5253         [images addObject:image];54     }5556     self.tom.animationImages = images; // 存儲了多張組成動畫的圖片5758     [self.tom setAnimationRepeatCount:1]; // 默認0是無限次59     [self.tom setAnimationDuration: images.count/FramesCount];60     [self.tom startAnimating];6162     [self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration + 1];63 }646566 @end
 
C.文檔注釋
使用塊注釋就能在輸入代碼自動完成的時候顯示注釋
/**      */

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 瓮安县| 正阳县| 措美县| 普兰县| 万州区| 昭平县| 崇阳县| 西畴县| 收藏| 桐乡市| 电白县| 高台县| 建昌县| 凯里市| 江油市| 新田县| 五大连池市| 钦州市| 台安县| 耒阳市| 景宁| 南城县| 迭部县| 枞阳县| 潞西市| 沾益县| 石楼县| 淳安县| 义马市| 长沙县| 衡阳市| 佛山市| 巫山县| 怀集县| 呼伦贝尔市| 芦溪县| 富平县| 聂拉木县| 繁峙县| 龙游县| 调兵山市|