objective-c 如何在 iOS 应用中捕获用户的手写签名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21241881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to capture user's handwritten signature in iOS app
提问by Nitya
In my app, user will request a digitized, handwritten signature from customers.
在我的应用程序中,用户将要求客户提供数字化的手写签名。
I need the ability to capture the signature as the user 'writes' it on the touchscreen. I also need to store an image of the digitized signature for future use.
我需要能够在用户在触摸屏上“书写”时捕获签名。我还需要存储数字化签名的图像以备将来使用。
I need help or pointers to enable my application to have digital signature?
我需要帮助或指示以使我的应用程序具有数字签名吗?
回答by Caleb
Since you're really talking about recording a user's "analog" signature on an iOS device, all you need to do is to create an image as the user moves a finger or stylus around a view. There are a number of tutorials on the web that illustrate that (here's one from Ray Wenderlich's site).
由于您实际上是在谈论在 iOS 设备上记录用户的“模拟”签名,因此您需要做的就是在用户围绕视图移动手指或手写笔时创建图像。网络上有许多教程可以说明这一点(这是Ray Wenderlich 网站上的一个)。
The basic idea is to build up a path by adding points as you track a touch in a view. When the user is done, you can save the resulting image itself or just save the path or paths. So, you'll probably create a subclass of UIViewcalled something like SignatureView, and you'll implement the touch-related responder methods -touchesBegan:withEvent:, -touchesMoved:withEvent:, -touchesEnded:withEvent:and -touchesCancelled:withEvent:. When a touch begins, you'll create a new bezier path. Each time the touch moves, add a point to that path. When the touch ends, add the new path to the list of paths that the view has recorded. You'll probably also want a method to erase the view by clearing the path list, as well as a -drawRect:method to draw the paths and some way for the view controller to retrieve the paths or image.
基本思想是通过在视图中跟踪触摸时添加点来构建路径。用户完成后,您可以保存生成的图像本身或只保存路径。所以,你可能会创建一个子类UIView叫像SignatureView,你会实现触控相关的应答方法-touchesBegan:withEvent:,-touchesMoved:withEvent:,-touchesEnded:withEvent:和-touchesCancelled:withEvent:。当触摸开始时,您将创建一条新的贝塞尔曲线路径。每次触摸移动时,向该路径添加一个点。当触摸结束时,将新路径添加到视图已记录的路径列表中。您可能还需要一种通过清除路径列表来擦除视图的方法,以及一种-drawRect:绘制路径的方法以及视图控制器检索路径或图像的某种方法。
Also, it should go without saying that you need to be extremely careful about what you do with a user's signature. Avoid storing unencrypted images of the signature, and perhaps avoid storing the signature on the device at all. You could instead send the signature to a server where it might be easier to protect.
此外,不用说,您需要非常小心对待用户签名的操作。避免存储未加密的签名图像,甚至完全避免将签名存储在设备上。您可以将签名发送到更容易保护的服务器。
回答by Randika Vishman
I guess these following links could help you! Anyway I found those while I's in search for the same purpose in the internet! Hope this works out for all of us!
我想以下这些链接可以帮助您!无论如何,我在互联网上寻找相同目的时找到了这些!希望这对我们所有人都有效!
The following links are regarding the same resource: Capturing handwritten Signature on iOS Devices.
以下链接与同一资源有关:在 iOS 设备上捕获手写签名。
- https://www.altamiracorp.com/blog/employee-posts/capture-a-signature-on-ios
- https://github.com/jharwig/PPSSignatureView
- http://java.dzone.com/articles/capture-signature-ios
- http://www.raywenderlich.com/18840/how-to-make-a-simple-drawing-app-with-uikit
- https://www.altamiracorp.com/blog/employee-posts/capture-a-signature-on-ios
- https://github.com/jharwig/PPSSignatureView
- http://java.dzone.com/articles/capture-signature-ios
- http://www.raywenderlich.com/18840/how-to-make-a-simple-drawing-app-with-uikit
Note:
As of today(13-Nov-2015), I noticed that the first link provided above from (altamiracorp.com) is not available for some unknown reason, may be they have put down their website. So I thought to publicly share one of my copies I have saved in EverNote, as it has some educational value theory wise. So please kindly access it here.
注意:
截至今天(2015 年 11 月 13 日),我注意到上面从 (altamiracorp.com) 提供的第一个链接由于某种未知原因无法使用,可能是他们已经关闭了他们的网站。所以我想公开分享我保存在 EverNote 中的一份副本,因为它具有一些教育价值理论。所以请在这里访问它。
Guess this answer helped you! :) (Y)
猜猜这个答案对你有帮助!:) (是)
回答by Vignesh Kumar
Please use apple research kit(http://www.apple.com/in/researchkit/)
请使用苹果研究工具包( http://www.apple.com/in/researchkit/)
See more details:
查看更多详情:
https://github.com/researchkit/researchkit
https://github.com/researchkit/researchkit
ViewController.h
视图控制器.h
#import <UIKit/UIKit.h>
#import <ResearchKit.h>
@interface ViewController : UIViewController<ORKTaskViewControllerDelegate> // Delegate
@property (strong, nonatomic) IBOutlet UIImageView *signImageview;
@property (nonatomic, strong, readonly) ORKConsentDocument *consentDocument;
@property (nonatomic, strong, readonly) ORKConsentSignature *signature;
ViewController.m
视图控制器.m
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_consentDocument = [[ORKConsentDocument alloc] init];
_signature = [[ORKConsentSignature alloc] init];
ORKConsentReviewStep *signatureStep = [[ORKConsentReviewStep alloc] initWithIdentifier:@"sign" signature:_signature inDocument:_consentDocument];
ORKOrderedTask *task =
[[ORKOrderedTask alloc] initWithIdentifier:@"task" steps:@[signatureStep]];
ORKTaskViewController *taskViewController = [[ORKTaskViewController alloc] initWithTask:task taskRunUUID:nil];
taskViewController.delegate = self;
[self presentViewController:taskViewController animated:YES completion:nil];
}
#pragma mark - ORKTaskViewController delegate method
- (void)taskViewController:(ORKTaskViewController *)taskViewController
didFinishWithReason:(ORKTaskViewControllerFinishReason)reason
error:(NSError *)error {
ORKConsentDocument *documentCopy = [_consentDocument copy];
ORKConsentSignatureResult *signatureResult =
(ORKConsentSignatureResult *)[[[taskViewController result] stepResultForStepIdentifier:@"sign"] firstResult];
[signatureResult applyToDocument:documentCopy];
self.signImageview.image = signatureResult.signature.signatureImage;
// Then, dismiss the task view controller.
[self dismissViewControllerAnimated:YES completion:nil];
}

