gpt4 book ai didi

iphone - 如何在 Objective-C 中用铅笔效果绘制签名?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:22:51 33 4
gpt4 key购买 nike

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

如何做这样的事情? (SignNow 应用程序)

谢谢

您可以在下面看到一些示例。 (首先使用我的代码,其次我想要相同的效果)

首先:

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

最佳答案

我建议在事件中获得一些灵感 smooth-drawing项目。这是开始和学习最佳实践的好地方。此外,您还可以在很棒的文章 drawing smooth lines with cocos2d 上了解更多关于这个项目背后的想法。 .

关于iphone - 如何在 Objective-C 中用铅笔效果绘制签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14810465/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com