我正在开发一个书写应用程序,我的书写工作正常,但我想要实现的是可变笔画宽度,这样书写就非常真实和直观,就像“< strong>BAMBOO”和“PENULTIMATE”应用程序。
首先我想告诉你我尝试过什么。
1) 根据我的研究,在 iOS 中,它们没有压力检测或速度检测。对于速度检测,我必须使用 OPENGL。
2)由于这些限制,我尝试使用本教程中给出的方法,该方法非常简单。这里是链接 http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-advanced-freehand-drawing-techniques/
3)这工作得很好,但这里发生的情况是,宽度随着我移动得更快而增加,随着我移动得更慢而减小。但我想要的是相反的效果,即当我移动较慢时宽度应该增加,而当我移动快速时,厚度应该只在边缘和整条线处可见。
这是 BAMBOO 应用程序和我的应用程序的屏幕截图。
1)BAMBOO应用程序
在上图中,线条是快速绘制的,您会看到厚度仅在边缘处。
2) 我的应用程序
在这里,您会看到线条在边缘处较细,而在其他地方较粗。
所以,这是我的疑问
1)除了我尝试过的之外,他们是否有更好的方法来满足我的要求。
2)如果我所尝试的方法是解决问题的正确方法,那么我需要做出哪些改变才能达到预期的效果。
问候 兰 git
最佳答案
如何扭转宽度行为的答案(甚至与您的问题相同)就在您发布的链接中。我所做的就是搜索“宽度”这个词
问题(我的突出显示不是引文的一部分):
The final version of this seems to work opposite of the first version. I would like to have the line thicker as the user moves slower and not thinner. Where do I change the code to inverse the final varying thickness to perform or like a pen? Meaning the slower the user moves the thicker or more ink the pen puts down... Thanks! Great tutorials, btw...
答案:
thanks for the great tutorial!
with these changes i got the opposite line width cahnge effect:
#define CAPACITY 100 #define FF 20.0 #define LOWER 0.01 #define UPPER 1.5 float frac1 = clamp(FF/len_sq(pointsBuffer[i], pointsBuffer[i+1]), LOWER, UPPER); // ................. (4) float frac2 = clamp(FF/len_sq(pointsBuffer[i+1], pointsBuffer[i+2]), LOWER, UPPER); float frac3 = clamp(FF/len_sq(pointsBuffer[i+2], pointsBuffer[i+3]), LOWER, UPPER);
在同一链接中对文本“float frac1 =”的另一次搜索显示,此更改应应用于第 76-78 行(文章代码中的 TouchMoved:withEvent: 内部的某个位置)
关于ios - 在iOS中绘制可变宽度的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21281278/