如何在iOS应用程序中捕获用户的手写签名 [英] How to capture user's handwritten signature in iOS app
问题描述
在我的应用中,用户将向客户请求数字化的手写签名。
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?
推荐答案
因为你真的在谈论在iOS设备上录制用户的模拟签名,所以你需要做的就是创建一个图像作为用户在视图周围移动手指或手写笔。网上有很多教程可以说明这些内容(这里是一个来自Ray Wenderlich的网站)。
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).
基本思路是在跟踪视图中的触摸时通过添加点来建立路径。用户完成后,您可以保存生成的图像本身或只保存路径。所以,您可能会创建一个 UIView
的子类,其名称类似于 SignatureView
,您将实现触摸 - 相关的响应方法 -touchesBegan:withEvent:
, -touchesMoved:withEvent:
, -touchesEnded: withEvent:
和 -touchesCancelled:withEvent:
。触摸开始时,您将创建一个新的贝塞尔曲线路径。每次触摸移动时,向该路径添加一个点。触摸结束时,将新路径添加到视图记录的路径列表中。您可能还需要一种通过清除路径列表来清除视图的方法,以及一个 -drawRect:
方法来绘制视图控制器的路径和某种方式检索路径或图像。
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 UIView
called 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.
此外,不用说你需要非常小心你对用户的签名做了什么。避免存储签名的未加密图像,也许避免将签名存储在设备上。您可以将签名发送到可能更容易保护的服务器。
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.
这篇关于如何在iOS应用程序中捕获用户的手写签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!