I have to make an application where i need digital signature for authentication before a transaction completes.
Now i do not know how to implement开发者_开发技巧 the same. My requirements are:-
- A screen where i can sign by swyping my fingers .
Now can anyone please tell me how to do make such a screen where i can sign using my fingers and it can be captured at the back.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
if ([touch tapCount] == 2) {
drawImage.image = nil;
return;
}
if ((lastPoint.x<17 && lastPoint.y < 116) || (lastPoint.x>287 && lastPoint.y >159))
NSLog(@"Outside");
else
{
lastPoint = [touch locationInView:vw];
// lastPoint.y -= 20;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:vw];
if ((currentPoint.x<17 && currentPoint.y < 116) || (currentPoint.x>287 && currentPoint.y >159))
NSLog(@"Outside");
else
{
UIGraphicsBeginImageContext(vw.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, vw.frame.size.width, vw.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastPoint = currentPoint;
mouseMoved++;
if (mouseMoved == 10) {
mouseMoved = 0;
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:vw];
if ([touch tapCount] == 2) {
drawImage.image = nil;
return;
}
if ((currentPoint.x<20 && currentPoint.y < 199) || (currentPoint.x>743 && currentPoint.y >425))
NSLog(@"Outside");
else
{
if(!mouseSwiped)
{
UIGraphicsBeginImageContext(vw.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, vw.frame.size.width, vw.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}
}
精彩评论