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的示例。