本文介绍了使用单点触控为 ios 构建具有电子签名功能的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这只是一个简单的问题,因为我在谷歌上搜索过并且只找到了已经具有此功能的应用程序 - 但是我如何着手创建一个能够捕获电子签名的应用程序......这可能吗?
This is just a quick question as I have googled and only found apps that already have this feature - but how do I go about creating an application that has the ability to capture electronic signatures...is this possible?
推荐答案
Xamarin 的组件商店有一个 执行此操作的签名板 组件.
Xamarin's Component Store has a Signature Pad component that does this.
我也从头开始写了类似的东西 - 这不是特别困难.代码看起来像这样:
I've also written something similar from scratch - it's not particularly difficult. The code would look something like this:
public class DrawView : UIView
{
DrawViewController dvc;
// clear the canvas
public void Clear ()
{
drawPath.Dispose ();
drawPath = new CGPath ();
fingerDraw = false;
SetNeedsDisplay ();
}
// pass in a reference to the controller, although I never use it
and could probably remove it
public DrawView (RectangleF frame, DrawViewController root) :
base(frame)
{
dvc = root;
this.drawPath = new CGPath ();
this.BackgroundColor = UIColor.White;
}
private PointF touchLocation;
private PointF prevTouchLocation;
private CGPath drawPath;
private bool fingerDraw;
public override void TouchesBegan (MonoTouch.Foundation.NSSet
touches, UIEvent evt)
{
base.TouchesBegan (touches, evt);
UITouch touch = touches.AnyObject as UITouch;
this.fingerDraw = true;
this.touchLocation = touch.LocationInView (this);
this.prevTouchLocation = touch.PreviousLocationInView (this);
this.SetNeedsDisplay ();
}
public override void TouchesMoved (MonoTouch.Foundation.NSSet
touches, UIEvent evt)
{
base.TouchesMoved (touches, evt);
UITouch touch = touches.AnyObject as UITouch;
this.touchLocation = touch.LocationInView (this);
this.prevTouchLocation = touch.PreviousLocationInView (this);
this.SetNeedsDisplay ();
}
public UIImage GetDrawingImage ()
{
UIImage returnImg = null;
UIGraphics.BeginImageContext (this.Bounds.Size);
using (CGContext context = UIGraphics.GetCurrentContext()) {
context.SetStrokeColor (UIColor.Black.CGColor);
context.SetLineWidth (5f);
context.SetLineJoin (CGLineJoin.Round);
context.SetLineCap (CGLineCap.Round);
context.AddPath (this.drawPath);
context.DrawPath (CGPathDrawingMode.Stroke);
returnImg = UIGraphics.GetImageFromCurrentImageContext ();
}
UIGraphics.EndImageContext ();
return returnImg;
}
public override void Draw (RectangleF rect)
{
base.Draw (rect);
if (this.fingerDraw) {
using (CGContext context = UIGraphics.GetCurrentContext()) {
context.SetStrokeColor (UIColor.Black.CGColor);
context.SetLineWidth (5f);
context.SetLineJoin (CGLineJoin.Round);
context.SetLineCap (CGLineCap.Round);
this.drawPath.MoveToPoint (this.prevTouchLocation);
this.drawPath.AddLineToPoint (this.touchLocation);
context.AddPath (this.drawPath);
context.DrawPath (CGPathDrawingMode.Stroke);
}
}
}
}
这篇关于使用单点触控为 ios 构建具有电子签名功能的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!