C# TouchMove事件在xamarin ios中结束得如此之快

C# TouchMove事件在xamarin ios中结束得如此之快,c#,.net,swift,xamarin,C#,.net,Swift,Xamarin,我创建了一个画布视图,如下所示。当我把它应用到一个新项目中时,它工作正常,但当我把它应用到我的实际项目中时,我不能画一条实线。它总是虚线(如下图所示)。第一次,我认为这是一个问题,因为我推了太多的屏幕,直到这个绘图。但每次我推送一个新视图时,我都试图禁用前一个视图的用户交互,但它不起作用。请帮忙 public class CanvasView : UIView { public CanvasView (CGRect frame) : base(frame) { t

我创建了一个画布视图,如下所示。当我把它应用到一个新项目中时,它工作正常,但当我把它应用到我的实际项目中时,我不能画一条实线。它总是虚线(如下图所示)。第一次,我认为这是一个问题,因为我推了太多的屏幕,直到这个绘图。但每次我推送一个新视图时,我都试图禁用前一个视图的用户交互,但它不起作用。请帮忙

public class CanvasView : UIView
{
    public CanvasView (CGRect frame) : base(frame)
    {
        this.drawPath = new CGPath();
        BackgroundColor = UIColor.White;

    }


    private CGPoint touchLocation;
    private CGPoint previousTouchLocation;
    private CGPath drawPath;
    private bool fingerDraw;
    public override void LayoutSubviews ()
    {
        base.LayoutSubviews ();
        Layer.BorderWidth = 0.5f;
        Layer.BorderColor = UIColor.FromRGB (146, 146, 146).CGColor;
    }
    public override void TouchesBegan (NSSet touches, UIEvent evt)
    {
        base.TouchesBegan (touches, evt);
        UITouch touch = touches.AnyObject as UITouch;
        this.fingerDraw = true;
        this.touchLocation = touch.LocationInView(this);
        this.previousTouchLocation = touch.PreviousLocationInView(this);

        this.SetNeedsDisplay();
    }
    public override void TouchesMoved (NSSet touches, UIEvent evt)
    {
        base.TouchesMoved (touches, evt);
        UITouch touch = touches.AnyObject as UITouch;
        this.touchLocation = touch.LocationInView(this);
        this.previousTouchLocation = touch.PreviousLocationInView(this);

        this.SetNeedsDisplay();
    }

    public override void TouchesEnded (NSSet touches, UIEvent evt)
    {
        base.TouchesEnded (touches, evt);
        var alert = new UIAlertView () {
            Message = "Xui"
        };
        alert.AddButton("OK");
        alert.Show();
    }
    public override void Draw (CGRect rect)
    {
        base.Draw (rect);
        if (this.fingerDraw)
        {
            using (CGContext context = UIGraphics.GetCurrentContext())
            {
                context.SetStrokeColor(UIColor.Black.CGColor);
                context.SetLineWidth(1.5f);
                context.SetLineJoin(CGLineJoin.Round);
                context.SetLineCap(CGLineCap.Round);
                this.drawPath.MoveToPoint(this.previousTouchLocation);
                this.drawPath.AddLineToPoint(this.touchLocation);
                context.AddPath(this.drawPath);
                context.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
    }
}

我认为问题不在于
触摸移动
,而在于您的绘图逻辑。当你调用
SetNeedsDisplay()
时,它并不意味着“现在绘制”,而是意味着“我有需要绘制的更改,所以亲爱的,在你可以的时候绘制我。”这意味着在处理绘图之前,会有更多的接触


在接到
Draw
调用之前,您必须保持上一个点不变,或者您必须将这些点放入缓冲区,并同时绘制它们。我会做第一个,因为它更简单。

但我不知道它在另一个项目上是如何工作的?请给我更多的细节!我试着按照你的建议去做,但还是这样:(