最近檢查代碼 發現了兩個問題 記錄一下~
解決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];
}];
最近使用虛線的時候 最開始發現虛線加載不出來,后來仔細想了想,可能是因為要添加虛線的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];
// 設置虛線顏色為
[shapeLayer setStrokeColor:lineColor.CGColor];
// 設置虛線寬度
[shapeLayer setLineWidth:CGRectGetHeight(lineView.frame)];
[shapeLayer setLineJoin:kCALineJoinRound];
// 設置線寬,線間距
[shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:lineLength], [NSNumber numberWithInt:lineSpacing], nil]];
// 設置路徑
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 {
//執行相應的邏輯
//兩層autoreleasepool的好處在于:
//內層的auto可以保證每次循環結束后清理一次內存,從而減少內存需求
}
}
}