Как будет выглядеть код, если вы хотите рисовать в классе UIImage?

аю приложение, в котором пользователь может что-то нарисовать пальцами ... Я понятия не имею, как я могу это сделать ...

После исследования я нашел код ниже.

Но с этим кодом я могу нарисовать только одну линию. Если касание завершено и начинается новое событие касания, линия продолжается в этой точке ... Старая линия автоматически подключается к новой.

Поэтому я хочу создать новую линию на каждом прикосновении.

Кто-нибудь знает, как это работает?

код

    CGPath path;
    CGPoint initialPoint;
    CGPoint latestPoint;

    public DrawView (IntPtr handle) : base (handle)
    {
        BackgroundColor = UIColor.White;

        path = new CGPath();
    }

    public override void TouchesBegan(NSSet touches, UIEvent evt)
    {
        base.TouchesBegan(touches, evt);

        UITouch touch = touches.AnyObject as UITouch;

        if (touch != null)
        {
            initialPoint = touch.LocationInView(this);
        }
    }

    public override void TouchesMoved(NSSet touches, UIEvent evt)
    {
        base.TouchesMoved(touches, evt);

        UITouch touch = touches.AnyObject as UITouch;

        if (touch != null)
        {
            latestPoint = touch.LocationInView(this);
            SetNeedsDisplay();
        }
    }

    public override void Draw(CGRect rect)
    {
        base.Draw(rect);

        if (!initialPoint.IsEmpty)
        {

            //get graphics context
            using (CGContext g = UIGraphics.GetCurrentContext())
            {
                //set up drawing attributes
                g.SetLineWidth(2);
                UIColor.Black.SetStroke();

                //add lines to the touch points
                if (path.IsEmpty)
                {
                    path.AddLines(new CGPoint[] { initialPoint, latestPoint });
                }
                else
                {
                    path.AddLineToPoint(latestPoint);
                }

                //add geometry to graphics context and draw it
                g.AddPath(path);

                g.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
    }

Ответы на вопрос(1)

Ваш ответ на вопрос