0
 UIGraphicsBeginImageContext(self.view.bounds.size);
        [currentStrokeImageView.image drawInRect:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeNormal);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), dWidth);
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), r, g, b, 1.0f);
        CGContextBeginPath(UIGraphicsGetCurrentContext());
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), pointA.x, pointA.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), pointB.x, pointB.y);
        CGContextStrokePath(UIGraphicsGetCurrentContext());
        currentStrokeImageView.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

出于某种原因,这在 iphone/ipod 上运行绝对没有滞后,但在 iPad 上,它们在绘图时有很大的滞后。我使用的代码在上面,有什么建议可以解决这个问题吗?

4

1 回答 1

3

之所以如此滞后,是因为您是在touchesMoved:withEvent:. 在接收到触摸事件时,可以(显然)多次调用此方法。因为绘制到图形上下文可能是一项资源密集型操作,所以我建议不要做你正在做的所有事情。我会尽可能地将您正在执行的渲染推迟到touchesBeginandtouchesEnd方法。如果这是不可能的,也许您只能在运动中达到某个增量(例如,每个2.0f点)后执行这些操作。

于 2011-09-30T22:28:48.680 回答