加速或优化持久性画笔

时间:2012-06-29 18:38:59

标签: iphone ios5 core-graphics 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;
 }

1 个答案:

答案 0 :(得分:0)

我发现改变了来自

的电话
[self setNeedsDisplay]

[self setNeedsDisplayInRect]

根据乐器

从1fps变为52fps