0
我用下面的代碼來創建一個手指畫種鍛鍊加快或優化持久的drawRect
當我在模擬器上運行一個持久的drawRect它是好的,當我在iPad上運行它被延遲在鋸齒線轉彎曲線可以請一些幫助一個優化或提出一個更好的方法提前
- (void)drawRect:(CGRect)rect
{
UIGraphicsPushContext(drawingContext);
CGImageRef cgImage = CGBitmapContextCreateImage(drawingContext);
image = [[UIImage alloc] initWithCGImage:cgImage];
if (draw) {
CGContextSetLineWidth(drawingContext, (2.0 * size));
CGContextSetStrokeColorWithColor(drawingContext, color);
CGContextSetLineCap(drawingContext,kCGLineCapRound);
CGContextMoveToPoint(drawingContext, lastPt.x - (31.0/self.transform.a), lastPt.y - (31.0/self.transform.a) );
CGContextAddLineToPoint(drawingContext, currPt.x - (31.0/self.transform.a), currPt.y - (31.0/self.transform.a) );
CGContextStrokePath(drawingContext);
} else {
// CGContextSetFillColorWithColor(drawingContext, [[UIColor redColor] CGColor]);
// CGContextFillRect(drawingContext, CGRectMake(currPt.x - (31.0/self.transform.a) - 16.0 , currPt.y - (31.0/self.transform.a) - 16.0 , 40.0 , 40.0));
CGContextClearRect(drawingContext, CGRectMake(currPt.x - (31.0/self.transform.a) - 16.0 , currPt.y - (31.0/self.transform.a) - 16.0 , 40.0 , 40.0));
}
UIGraphicsPopContext();
CGImageRelease(cgImage);
NSLog(@" %@ " , rect);
[image drawInRect: rect];
lastPt = currPt;
}