开发者

CGContext Draw Line slowly responding to fast finger movement

I am using CGContext to draw lines on finger touch. If the finger is moved slowly on the screen , it worked perfectly...but the problem is that if the finger is moved fastly , the line lags the finger. I mean the line draws at a point one second after the finger is touched at that point ( so annoying- it is not the problem on simulator but only on device). Secondly if i draw a curve with that, the curve comes very angular - i mean curve is not very smooth Please help ( I dont want to use OpenGL, is there any other solution)

EDIT:-

Sorry but I am a noobe...dont know too much about what hotpaw has said below...but this is my code

-(void) draw rect{
CGContextBeginPath(ctx);
CGContextMoveToPoint(ctx, beginpointX, beginpointY);
CGContextSetStrokeColorWithColor(ct开发者_Go百科x, CGColor);
CGContextAddLineToPoint(ctx,currentpointX,currentpointY);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextStrokePath(ctx);
CGContextSetLineJoin(ctx, kCGLineJoinRound);
CGContextClosePath(ctx);

and in my touchesBegan and touchesmoved method i am calling view's setNeedsDisplay method.

dont know how many frames/second or touches event are there...please help its very urgent


I found the answer for my second question i.e. drawing smooth non-angular curves. for that u have to use quad curves . i found this answer at many places but couldnot find how to use quad curves ..somehow i figured out from some android example and so i will post the basic idea here... suppose u r geetting the points on finger touch (by touchesmoved method) like firstpoint, secondpoint, thirdpoint and so on then

 CGContextMovetoPoint(ctx,firstpoint); CGContextAddQuadCurveToPoint(context,secondpoint.x,secondpoint.y,(secondpoint.x+thirdpoint.x)/2,(secondpoint.y+thirdpoint.y)/2);
CGContextAddQuadCurveToPoint(context,thirdpoint.x,thirdpoint.y,(thirdpoint.x+forthpoint.x)/2,(thirdpoint.y+forthpoint.y)/2);

and so on...


At what frame rate are you (re)drawing and at what rate are the touchesMoved event coming in? There's no value in drawing faster than 30 to 60 frames per second. If you are trying (re)draw your line more times per second than that, then you could be blocking your UI responder chain and losing touch move events, as well as wasting CPU/GPU/Battery.

Look at one of Apple's example apps for how to do this. (GLPaint? FingerPaint?)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜