ios - 为 ios 构建具有电子签名功能的应用程序可能使用单触摸?

标签 ios objective-c xamarin.ios

这只是一个简单的问题,因为我在谷歌上搜索过并且只找到了已经具有此功能的应用程序 - 但是我如何着手创建一个能够捕获电子签名的应用程序......这可能吗?

最佳答案

Xamarin 的组件商店有一个 Signature Pad执行此操作的组件。

我也从头开始写过类似的东西——不是特别难。代码看起来像这样:

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 - 为 ios 构建具有电子签名功能的应用程序可能使用单触摸?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17219426/

相关文章:

ios - 日期选择器在 swift 2.2 中首次单击文本字段时无法打开

ios - 如何在 ipad 应用程序中单击 uiimage 时打开 View (另一个 xib)

ios - 如何为IOS中的所有 View 实现一个通用的标签栏?

objective-c - 强制 UISearchController 全屏显示搜索结果表

objective-c - 如何加入 [Number numberWithChar : c]'s into an NSString?] 的 NSArray

ios - 如何向多行 UILabel 添加缩进?

ios - "Initializer for conditional binding must have Optional type, not ' [字符串] '"

objective-c - 失败,但没有返回错误对象。为什么?

ios - 如何在 iOS 11.4 的 Xamarin Forms 中为编辑器/条目自动大写文本

c# - monotouch 中的 Mysql 连接问题