How to fill space between two UIBezierPaths

2019-06-10 03:16发布

问题:

I'm working on drawing application which provides drawing lines with variable line width which depends on drawing speed. This behavior inspired by Paper app.

Algorithm which I'm trying to implement -- draw two bezier path with variable distance between them. The solution which described in sosborn's answer. Then smooth paths and fill the distance between them.

Actually I don't figured out how to fill space between paths.

回答1:

You create a single path from the 2 bezier curves and fill it, like this:

NSBezierPath* path = [NSBezierPath bezierPath];

// Move to the start point
[path moveToPoint:startPt];

// Make the lower part of the curve
[path curveToPoint:endPt controlPoint1:cp1 controlPoint2:cp2];

// Make the upper part of the curve as part of the same path:
[path curveToPoint:startPt contorPoint1:cp3 controlPoint2:cp4];

// Now fill it
[path fill];