## 九宮格計(jì)算思路
- 利用控件的索引index計(jì)算出控件所在的行號(hào)和列號(hào)
- 利用列號(hào)計(jì)算控件的x值
- 利用行號(hào)計(jì)算控件的y值
eg:
// 每一個(gè)商品的尺寸
CGFloat shopW = 80;
CGFloat shopH = 90;
// 一行的列數(shù)
int cols = 3;
// 每一列之間的間距
CGFloat colMargin = (self.shopsView.frame.size.width - cols * shopW) / (cols - 1);
// 每一行之間的間距
CGFloat rowMargin = 10;
// 創(chuàng)建一個(gè)父控件(整體:存放圖片和文字)
UIView *shopView = [[UIView alloc] init];
shopView.backgroundColor = [UIColor redColor];
// 商品的索引
NSUInteger index = self.shopsView.subviews.count;
// 商品的x值
NSUInteger col = index % cols;
CGFloat shopX = col * (shopW + colMargin);
// 商品的y值
NSUInteger row = index / cols;
CGFloat shopY = row * (shopH + rowMargin);
shopView.frame = CGRectMake(shopX, shopY, shopW, shopH);
[self.shopsView addSubview:shopView];
## HUD
- 其他說(shuō)法:指示器、遮蓋、蒙板
- 半透明HUD的做法
- 背景色設(shè)置為半透明顏色
## 定時(shí)任務(wù)
- 方法1:performSelector
```objc
// 1.5s后自動(dòng)調(diào)用self的hideHUD方法
[self performSelector:@selector(hideHUD) withObject:nil afterDelay:1.5];
```
- 方法2:GCD
```objc
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 1.5s后自動(dòng)執(zhí)行這個(gè)block里面的代碼
self.hud.alpha = 0.0;
});
```
- 方法3:NSTimer
```objc
// 1.5s后自動(dòng)調(diào)用self的hideHUD方法
[NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(hideHUD) userInfo:nil repeats:NO];
// repeats如果為YES,意味著每隔1.5s都會(huì)調(diào)用一次self的hidHUD方法
```
## 常見(jiàn)問(wèn)題
- 項(xiàng)目里面的某個(gè).m文件無(wú)法使用
- 檢查:Build Phases -> Compile Sources
- 項(xiàng)目里面的某個(gè)資源文件(比如plist、音頻等)無(wú)法使用
- 檢查:Build Phases -> Copy Bundle Resources
## 模型
- 什么是模型?
- 專門用來(lái)存放數(shù)據(jù)的對(duì)象
- 一般都是一些直接繼承自NSObject的純對(duì)象
- 內(nèi)部會(huì)提供一些屬性來(lái)存放數(shù)據(jù)
## 一個(gè)控件看不見(jiàn)有哪些可能?
- 寬度或者高度其實(shí)為0
- 位置不對(duì)(比如是個(gè)負(fù)數(shù)或者超大的數(shù),已經(jīng)超出屏幕)
- hidden == YES
- alpha <= 0.01
- 沒(méi)有設(shè)置背景色、沒(méi)有設(shè)置內(nèi)容
- 可能是文字顏色和背景色一樣