Coregraphics在iPad上造成很大的滞后? [英] Coregraphics causing big lag on iPad?
问题描述
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上,它们在绘制时是相当大的滞后.我上面使用的代码是否有解决此问题的建议?
For some reason this runs with absolutely no lag on the iphone/ipod but on the iPad their is a significant lag while drawing. The code I use is above, any suggestions to fix this?
推荐答案
之所以如此冗长,是因为您正在touchesMoved:withEvent:
中执行此操作.接收到触摸事件时,可以多次(很明显)调用此方法.因为绘制到图形上下文可能是一项资源密集型操作,所以我建议不执行您在此处所做的所有事情.我将尽可能地将您正在执行的渲染推迟到touchesBegin
和touchesEnd
方法.如果这不可能,那么只有在运动中达到某个增量后,例如,每个2.0f
点,您才可以执行这些操作.
The reason why this is so laggy is because you are doing it in the touchesMoved:withEvent:
. This method can be called many, many times (obviously) while touch events are received. Because drawing to a graphics context can be a resource intensive operation, I would recommend not doing all the things you are doing there. I would, as much as possible, defer the rendering you are doing to the touchesBegin
and touchesEnd
methods. If that is not possible, perhaps you could only preform these operations once a certain delta has been reached in the movements, for example, every 2.0f
points.
这篇关于Coregraphics在iPad上造成很大的滞后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!