最近檢查代碼 發(fā)現(xiàn)了兩個問題 記錄一下~
解決CollectionView reloadData或者reloadSections時的刷新的閃爍問題
將你原來的reloadData reloadSections像這樣包一下:
[UIView performWithoutAnimation:^{
[self.mainCol performBatchUpdates:^{
[self.mainCol reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.mainCol.numberOfSections)]];
[self.mainCol reloadEmptyDataSet];
} completion:nil];
}];
最近使用虛線的時候 最開始發(fā)現(xiàn)虛線加載不出來樱报,后來仔細(xì)想了想,可能是因為要添加虛線的UIView都還沒有渲染完畢民珍,所以才沒加出來盗飒,果然實驗了一下就是這樣,切記~
- 虛線
/**
在制定的view上添加虛線
@param lineView 需要添加虛線的view
@param lineLength 虛線長度
@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);
// 把繪制好的虛線添加上來
[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)存需求
}
}
}