【问题标题】:Speed up or optimize persistent drawrect加速或优化持久drawrect
【发布时间】:2012-06-29 18:38:59
【问题描述】:

我正在使用以下代码为手指绘画类型练习创建一个持久的 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;
 }

【问题讨论】:

    标签: iphone ios5 core-graphics drawrect


    【解决方案1】:

    我发现更改呼叫来自

    [self setNeedsDisplay]
    

    [self setNeedsDisplayInRect]
    

    根据仪器从 1fps 更改为 52fps

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-10
      • 2020-12-15
      • 2014-09-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多