iPhone signature capture

前端 未结 1 625
隐瞒了意图╮
隐瞒了意图╮ 2021-02-10 18:38

Is it possible to transfer a signature from an iPhone into an .xls file via a cable (USB) connection?

1条回答
  •  攒了一身酷
    2021-02-10 19:06

    So, this may not be exactly what you are looking for, but this is how I capture a signature drawn by a user (with their finger/stylus). Your UIImageView will have the drawn signature. I have not thought about how to transfer the signature image to the .xls but you could save the image to the device's photo library then export it like you would any other image, then drop it into the .xls (I know, that's a manual process). I hope this helps.

    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();
        }
    }
    

    0 讨论(0)
提交回复
热议问题