Closed ismaiI1 closed 6 years ago
After successfully saved signature, you can download it from NSUserDefaults.
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:USER_SIGNATURE_PATH];
NSMutableArray *signPathArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
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 :) 👍
Hi,
I need to get array of points (x,y) from UIBezierPath in Obj-C. How can i get it?