如何在目标C中用铅笔效果绘制签名?

时间:2013-02-11 10:39:05

标签: iphone ios objective-c uikit draw

我尝试根据绘图效果开发一个新的应用程序。我知道简单的效果,但我看到一些带有画笔效果的应用程序(铅笔效果)。

怎么做这样的想法? (SignNow app)

谢谢

您可以在下面看到一些示例。 (首先是我的代码,第二个我想要相同的效果)

首先:

myapp drawing a signature

第二:

signnow app i want same

我的代码:

- (void)drawRect:(CGRect)rect {

CGContextRef context = UIGraphicsGetCurrentContext();

// Set drawing params
CGContextSetLineWidth(context, self.lineWidth);
CGContextSetStrokeColorWithColor(context, [self.foreColor CGColor]);
CGContextSetLineCap(context, kCGLineCapButt);
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextBeginPath(context);




// This flag tells us to move to the point
// rather than draw a line to the point
BOOL isFirstPoint = YES;

// Loop through the strings in the array
// which are just serialized CGPoints
for (NSString *touchString in self.handwritingCoords) {

    // Unserialize
    CGPoint tapLocation = CGPointFromString(touchString);

    // If we have a CGPointZero, that means the next
    // iteration of this loop will represent the first
    // point after a user has lifted their finger.
    if (CGPointEqualToPoint(tapLocation, CGPointZero)) {
        isFirstPoint = YES;
        continue;
    }


    // If first point, move to it and continue. Otherwize, draw a line from
    // the last point to this one.
    if (isFirstPoint) {
        CGContextMoveToPoint(context, tapLocation.x, tapLocation.y);




            //CGContextAddArc(ctx, tapLocation.x, tapLocation.y, 30.00, (startDeg-90)*M_PI/180.0, (endDeg-90)*M_PI/180.0, 0);
        isFirstPoint = NO;
    } else {
        CGPoint startPoint = CGContextGetPathCurrentPoint(context);
        CGContextAddQuadCurveToPoint(context, startPoint.x, startPoint.y, tapLocation.x, tapLocation.y);
        CGContextAddLineToPoint(context, tapLocation.x, tapLocation.y);
    }

}   

// Stroke it, baby!
CGContextStrokePath(context);

}

1 个答案:

答案 0 :(得分:0)

我建议您对活跃的smooth-drawing项目有所启发。这是一个开始和学习最佳实践的好地方。此外,您可以在精彩文章drawing smooth lines with cocos2d上了解有关此项目背后的思考的更多信息。