2010-11-09 41 views
4

是否可以通过电缆(USB)连接将签名从iPhone传输到.xls文件?iPhone签名捕获

+0

什么样的签名? – 2010-11-09 14:03:54

+0

来自应用的签名,如autogragh。例如一位签署收货的客户。 – 2010-11-09 14:46:22

+0

您正在寻找一种方法来捕获签名,或者只有通过标准附件端口/ USB将它从应用程序导出到Excel的方式? – JWD 2010-11-09 16:07:33

回答

7

所以,这可能不是你正在寻找的,但这是我如何捕捉用户(用他们的手指/手写笔)绘制的签名。您的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(); 
    } 
} 
+0

这似乎很棒。我很想看到完整的.h,并且更多地介绍如何通过界面生成器实际整合这个。 – radven 2012-06-28 06:13:27