vigneshuvi / iOS-Signature-Capture

iOS-Signature-Capture is helps to capture the user signature with name and signed date in iOS and supports both Objective-c and Swift languages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can i get points array?

ismaiI1 opened this issue · comments

Hi,

I need to get array of points (x,y) from UIBezierPath in Obj-C. How can i get it?

ekran resmi 2017-12-06 14 10 40

After successfully saved signature, you can download it from NSUserDefaults.

    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:USER_SIGNATURE_PATH];
    NSMutableArray *signPathArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];

Get Path Array - Example

I can get Path array, but i need x and y coordinates of all points.

Find coordinates of path.

`-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self becomeFirstResponder];

NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:USER_SIGNATURE_PATH];
NSMutableArray *signPathArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
[self.signatureView setPathArray:signPathArray];
[self.signatureView setNeedsDisplay];

for (UIBezierPath *path in signPathArray) {
    NSMutableArray *keyPoints = [NSMutableArray array];
    CGPathApply(path.CGPath, (__bridge void * _Nullable)(keyPoints), printPathXY);
}

}

void printPathXY (void *info, const CGPathElement *element) {
CGPathElementType type = element->type;
CGPoint point = *element->points;
if (type != kCGPathElementCloseSubpath)
{
if ((type == kCGPathElementAddLineToPoint) ||
(type == kCGPathElementMoveToPoint))
NSLog(@"x:%f, y:%f",point.x, point.y);
else if (type == kCGPathElementAddQuadCurveToPoint)
NSLog(@"x:%f, y:%f",point.x, point.y);
else if (type == kCGPathElementAddCurveToPoint)
NSLog(@"x:%f, y:%f",point.x, point.y);
}
}
`

Find coordinates of path:

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self becomeFirstResponder];
    
    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:USER_SIGNATURE_PATH];
    NSMutableArray *signPathArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    [self.signatureView setPathArray:signPathArray];
    [self.signatureView setNeedsDisplay];
    
    for (UIBezierPath *path in signPathArray) {
        NSMutableArray *keyPoints = [NSMutableArray array];
        CGPathApply(path.CGPath, (__bridge void * _Nullable)(keyPoints), printPathXY);
    }
}

void printPathXY (void *info, const CGPathElement *element) {
    CGPathElementType type = element->type;
    CGPoint point = *element->points;
    if (type != kCGPathElementCloseSubpath)
    {
        if ((type == kCGPathElementAddLineToPoint) ||
            (type == kCGPathElementMoveToPoint))
                NSLog(@"x:%f, y:%f",point.x, point.y);
        else if (type == kCGPathElementAddQuadCurveToPoint)
            NSLog(@"x:%f, y:%f",point.x, point.y);
        else if (type == kCGPathElementAddCurveToPoint)
            NSLog(@"x:%f, y:%f",point.x, point.y);
    }
}

Thanks :) 👍