захват подписи iPhone - PullRequest
       19

захват подписи iPhone

4 голосов
/ 09 ноября 2010

Можно ли передать подпись с iPhone в файл .xls по кабелю (USB)?

1 Ответ

7 голосов
/ 09 ноября 2010

Итак, это может быть не совсем то, что вы ищете, но именно так я фиксирую подпись, нарисованную пользователем (его пальцем / стилусом). Ваш UIImageView будет иметь нарисованную подпись. Я не задумывался о том, как перенести изображение подписи в файл .xls, но вы можете сохранить изображение в библиотеке фотографий устройства, затем экспортировать его, как любое другое изображение, а затем поместить его в файл .xls (я знаю, это руководство процесс). Надеюсь, это поможет.

SignatureViewController.h

IBOutlet UIImageView *signatureImageView;

//Signature Drawing Items
CGPoint lastPoint;
BOOL mouseSwiped;   
int mouseMoved;

SignatureCaptureViewController.m

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {      
    mouseSwiped = NO;
    UITouch *touch = [touches anyObject];

    //Clear Signature on Double Tap
    if ([touch tapCount] == 2) {
        signatureImageView.image = nil;
        return;
    }

    lastPoint = [touch locationInView:signatureImageView];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    mouseSwiped = YES;

    UITouch *touch = [touches anyObject];   

    CGPoint currentPoint = [touch locationInView:signatureImageView];

    UIGraphicsBeginImageContext(signatureImageView.frame.size);
    [signatureImageView.image drawInRect:CGRectMake(0, 0, signatureImageView.frame.size.width, signatureImageView.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.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());

    signatureImageView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];

    //Clear Signature on Double Tap
    if ([touch tapCount] == 2) {
        signatureImageView.image = nil;
        return;
    }

    if(!mouseSwiped) {
        UIGraphicsBeginImageContext(signatureImageView.frame.size);
        [signatureImageView.image drawInRect:CGRectMake(0, 0, signatureImageView.frame.size.width, signatureImageView.frame.size.height)];
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 2.0);
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 0.0);
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextStrokePath(UIGraphicsGetCurrentContext());
        CGContextFlush(UIGraphicsGetCurrentContext());
        signatureImageView.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
}
...