Calculate controlPoints while drawing in iOS

前端 未结 1 888
挽巷
挽巷 2020-12-11 07:39

I am working on a drawing app, where user can draw/write with his finger or stylus. For this I have referred code from https://github.com/yusenhan/Smooth-Line-View

相关标签:
1条回答
  • 2020-12-11 07:58

    The problem you're having is that when the user drags his finger slowly, the control points you get are too far apart, so you get large line segments rather than the small pixel changes that would give you a smooth-looking curve.

    Calcualting Bezier control points from an existing curve is really hard, since the control points are not on the line.

    Better to use Catmull-Rom curves. There is an excellent "Recipe" in Erica Sadun's OUTSTANDING book "The Advanced iOS 6 Developer's Cookbook" that includes working code on Catmull-Rom spline based smoothing. Catmull-Rom splines use control points that are on the curve.

    I highly recommend buying that book. The sample code for Recipe 4.3 will do exactly what you want.

    0 讨论(0)
提交回复
热议问题