Как подписать с помощью мыши в Iphone - PullRequest
2 голосов
/ 12 апреля 2011

Мне нужно подать заявление, в котором мне нужна цифровая подпись для аутентификации до завершения транзакции.

Теперь я не знаю, как реализовать то же самое.Мои требования: -

  1. Экран, на котором я могу подписать, проводя пальцами.

Теперь кто-нибудь может сказать мне, как сделать такой экран, где я могуподписать, используя мои пальцы, и это может быть захвачено на спине.

1 Ответ

4 голосов
/ 12 апреля 2011
- (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();
        }
    }
}
...