最近檢查代碼 發(fā)現(xiàn)了兩個(gè)問(wèn)題 記錄一下~
解決CollectionView reloadData或者reloadSections時(shí)的刷新的閃爍問(wèn)題
將你原來(lái)的reloadData reloadSections像這樣包一下:
[UIView performWithoutAnimation:^{
[self.mainCol performBatchUpdates:^{
[self.mainCol reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.mainCol.numberOfSections)]];
[self.mainCol reloadEmptyDataSet];
} completion:nil];
}];
最近使用虛線的時(shí)候 最開(kāi)始發(fā)現(xiàn)虛線加載不出來(lái),后來(lái)仔細(xì)想了想,可能是因?yàn)橐砑犹摼€的UIView都還沒(méi)有渲染完畢,所以才沒(méi)加出來(lái),果然實(shí)驗(yàn)了一下就是這樣,切記~
- 虛線
/**
在制定的view上添加虛線
@param lineView 需要添加虛線的view
@param lineLength 虛線長(zhǎng)度
@param lineSpacing 虛線與虛線之間的間隔
@param lineColor 虛線的顏色
*/
- (void)drawDashLine:(UIView *)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor *)lineColor {
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setBounds:lineView.bounds];
[shapeLayer setPosition:CGPointMake(CGRectGetWidth(lineView.frame) / 2, CGRectGetHeight(lineView.frame))];
[shapeLayer setFillColor:[UIColor clearColor].CGColor];
// 設(shè)置虛線顏色為
[shapeLayer setStrokeColor:lineColor.CGColor];
// 設(shè)置虛線寬度
[shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
[shapeLayer setLineJoin:kCALineJoinRound];
// 設(shè)置線寬,線間距
[shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
// 設(shè)置路徑
CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddLineToPoint(path, NULL, CGRectGetWidth(lineView.frame), 0); [shapeLayer setPath:path]; CGPathRelease(path);
// 把繪制好的虛線添加上來(lái)
[lineView.layer addSublayer:shapeLayer];
}
還是這樣使用:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self drawDashLine:self.alpaLineOne lineLength:4 lineSpacing:1 lineColor:[UIColor blackColor]];
[self drawDashLine:self.alpaLineTwo lineLength:4 lineSpacing:1 lineColor:[UIColor blackColor]];
});
合理使用@autoreleasepool
@autoreleasepool {
NSUInteger userCount = 100;
for (NSUInteger i = 0; i < userCount; i ++) {
@autoreleasepool {
//執(zhí)行相應(yīng)的邏輯
//兩層autoreleasepool的好處在于:
//內(nèi)層的auto可以保證每次循環(huán)結(jié)束后清理一次內(nèi)存,從而減少內(nèi)存需求
}
}
}