Iphone 加速或优化持久drawrect
我使用下面的代码为手指绘画类型练习创建一个持久的DrawRect 当我在模拟器上运行时,它是好的,当我在iPad上运行时,它会以锯齿线延迟转弯。有人能帮助优化或建议更好的方法吗 提前谢谢Iphone 加速或优化持久drawrect,iphone,ios5,core-graphics,drawrect,Iphone,Ios5,Core Graphics,Drawrect,我使用下面的代码为手指绘画类型练习创建一个持久的DrawRect 当我在模拟器上运行时,它是好的,当我在iPad上运行时,它会以锯齿线延迟转弯。有人能帮助优化或建议更好的方法吗 提前谢谢 - (void)drawRect:(CGRect)rect { UIGraphicsPushContext(drawingContext); CGImageRef cgImage = CGBitmapContextCreateImage(drawingContext); image = [[UIIm
- (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;
}
我发现把电话从
[self setNeedsDisplay]
到
根据仪器从1fps变为52fps
[self setNeedsDisplayInRect]