我有一個很好的簽名控件,除非您有一個長名稱,然後開始顯示空白。似乎與性能有關,但在模擬器和最新的iPad上都是一樣的。我附上了一個示例項目以及簽名圖形代碼。在iOS中捕獲簽名時的性能問題
任何幫助將不勝感激!
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, 112, 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;
}
}
}
我認爲這是可能的表現有關。我能夠在視網膜iPad上重現您的問題,但不是正常的問題。 –