Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 画一次图像,然后用手指在上面画(单触)_Ios_Xamarin.ios_Xamarin - Fatal编程技术网

Ios 画一次图像,然后用手指在上面画(单触)

Ios 画一次图像,然后用手指在上面画(单触),ios,xamarin.ios,xamarin,Ios,Xamarin.ios,Xamarin,我现在可以画一幅画,然后用手指画,代码如下: public override void Draw (RectangleF rect) { base.Draw (rect); using (CGContext context = UIGraphics.GetCurrentContext()) { // Draw image in context context.DrawImage (

我现在可以画一幅画,然后用手指画,代码如下:

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

            using (CGContext context = UIGraphics.GetCurrentContext()) {

                // Draw image in context
                context.DrawImage (rectangle, imageToDraw.CGImage);


                 // Draw finger touch
                if (this.fingerDraw) {

                    context.SetStrokeColor (UIColor.Black.CGColor);
                    context.SetLineWidth (5f);
                context.SetLineCap (CGLineCap.Round);

                    this.drawPath.MoveToPoint (this.prevTouchLocation);
                    this.drawPath.AddLineToPoint (this.touchLocation);
                    context.AddPath (this.drawPath);
                    context.DrawPath (CGPathDrawingMode.Stroke);

                }
            }  
    }
然而,这给我带来了性能问题,每次用户触摸屏幕时绘制图像是非常昂贵的


如何在开始时绘制一次图像,然后仅绘制手指触摸?

不要在图像上绘制。将图像放在手指画视图下方的视图中。

感谢Ian的回答。你有这样的小例子吗?创建一个UIImageView并将其添加到层次结构中,然后再添加在其中进行绘图的视图。我相信您可以找到许多关于如何在swift中添加UIImageView的示例。