在iOS中捕获签名时的性能问题

在iOS中捕获签名时的性能问题,第1张

概述我有一个很好用的签名控件,除非你有一个很长的名字然后它开始显示差距.似乎与性能有关,但在模拟器和最新的iPad上都是一样的.我在下面附上了一个示例项目和签名图纸代码. 任何帮助将非常感谢! https://dl.dropboxusercontent.com/u/25670071/SignatureArchive.zip using System; using MonoTouch.UIKit; 我有一个很好用的签名控件,除非你有一个很长的名字然后它开始显示差距.似乎与性能有关,但在模拟器和最新的iPad上都是一样的.我在下面附上了一个示例项目和签名图纸代码.

任何帮助将非常感谢!

https://dl.dropboxusercontent.com/u/25670071/SignatureArchive.zip

using System; using Monotouch.UIKit; using Monotouch.CoreGraphics; using System.Drawing;namespace MyApp{  public class SignatureVIEwV2 : UIVIEw  {         public delegate voID SignatureChanged();    public SignatureChanged OnSignatureChanged;    private bool _empty = true;    // clear the canvas    public voID Clear ()    {        drawPath.dispose ();        drawPath = new CGPath ();        fingerDraw = false;        SetNeedsdisplay ();        _empty = true;    }    public bool IsEmpty ()    {        return _empty;    }    public SignatureVIEwV2 (RectangleF frame) : base(frame)    {        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 Draw (RectangleF rect)    {        base.Draw (rect);        if (this.fingerDraw) {            using (CGContext context = UIGraphics.GetCurrentContext()) {                context.Setstrokecolor (UIcolor.FromrGB(63,112,185).CGcolor);                context.Setlinewidth (2f);                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);            }            if(OnSignatureChanged != null)                OnSignatureChanged();            _empty = false;        }        }    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.FromrGB(63,185).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;    }}

}

解决方法 你不能依赖每个touchesMoved()调用Draw().如果每2次触摸调用Draw(),就会得到所描述的间隙.

我通过排队(例如在队列< T>中)触摸touchesMoved()中的触摸并在Draw()中出列来解决这个问题.

您可能还有另一个问题:在每个Draw()时,您每次都会重新添加当前路径的完整路径.您可以通过仅为新段调用Addpath或调用Addpath()一次,将路段添加到路径(“Move,Addline”并重新绘制它)来解决此问题.但我还没有测试过这些.

总结

以上是内存溢出为你收集整理的在iOS中捕获签名时的性能问题全部内容,希望文章能够帮你解决在iOS中捕获签名时的性能问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1065267.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存