文章預(yù)讀
內(nèi)存惡鬼drawRect - 談畫圖功能的內(nèi)存優(yōu)化
根據(jù)文中提到的解決內(nèi)存問題有這重要的兩點(diǎn):
①盡量不用drawRect進(jìn)行繪圖
②如果要用溯革,也盡量減小畫布
第一點(diǎn)中我們采用何種方式來代替呢,最好是用CAShapLayer,然后配合UIBezierPath來做瓷炮。
貼一段代碼看下:
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(point1X, point1Y)];
[path addLineToPoint:CGPointMake(point2X, point2Y)];
[path addLineToPoint:CGPointMake(point3X, point3Y)];
[path addLineToPoint:CGPointMake(point4X, point4Y)];
[path closePath];
//[path fill];
CAShapeLayer *shapeLayer = [[CAShapeLayer alloc] init];
shapeLayer.path = path.CGPath;
shapeLayer.fillColor = randomColor.CGColor;
shapeLayer.lineCap = kCALineCapRound;
shapeLayer.lineJoin = kCALineJoinRound;
shapeLayer.strokeColor = [UIColor clearColor].CGColor;
shapeLayer.lineWidth = path.lineWidth;
[self.layer addSublayer:shapeLayer];
附錄