這篇整理幾個日常開發中反覆用到的觀念與排錯要點,都是實作時容易卡住的小環節。
關鍵在於把一維的索引換算成二維座標,其餘就是寬高與間距的乘法與加法。
方法一,使用 performSelector:
[self performSelector:@selector(hideHUD) withObject:nil afterDelay:1.5];
方法二,使用 GCD:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
self.hud.alpha = 0.0;
});
方法三,使用 NSTimer:
[NSTimer scheduledTimerWithTimeInterval:1.5
target:self
selector:@selector(hideHUD)
userInfo:nil
repeats:NO];
其中 repeats 設為 YES 時,代表每隔 1.5 秒就會呼叫一次。
hidden == YESalpha <= 0.01把這幾項當成 checklist 逐一排除,通常很快就能找到原因。