CGContext绘制线缓慢响应快速手指移动 [英] CGContext Draw Line slowly responding to fast finger movement

查看:36
本文介绍了CGContext绘制线缓慢响应快速手指移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CGContext在手指触摸上绘制线条. 如果手指在屏幕上缓慢移动,则效果很好...但是问题是,如果手指快速移动,则线条会滞后于手指.我的意思是该线在手指触摸该点一秒钟后在一点上绘制(所以很烦人-这不是模拟器上的问题,而仅仅是设备上的问题). 其次,如果我以此绘制一条曲线,则该曲线会非常有角度-我的意思是曲线不是很平滑 请帮忙(我不想使用OpenGL,是否还有其他解决方案)

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)

-

对不起,但我是个菜鸟...不要对hotpaw在下面说的话了解得太多...但这是我的代码.

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(ctx, CGColor);
CGContextAddLineToPoint(ctx,currentpointX,currentpointY);
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextStrokePath(ctx);
CGContextSetLineJoin(ctx, kCGLineJoinRound);
CGContextClosePath(ctx);

,在我的touchesBegantouchesmoved方法中,我正在调用view的setNeedsDisplay方法.

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

推荐答案

我找到了第二个问题的答案,即绘制平滑的非角度曲线.为此,您必须使用四边形曲线.我在很多地方找到了这个答案,但找不到如何使用四边形曲线..以某种方式我从一些android示例中找出来,因此我将在此处发布基本思想... 假设您通过触摸移动方法获取手指触摸的点,例如第一点,第二点,第三点等等

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);

以此类推...

这篇关于CGContext绘制线缓慢响应快速手指移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆