gpt4 book ai didi

c# - 如何使用 SkiaSharp 在 Xamarin 中创建简单的动画

转载 作者:行者123 更新时间:2023-12-04 10:50:01 25 4
gpt4 key购买 nike

如何创建调用 DrawCircle 或 DrawLine 函数的简单动画。

public void DrawCircle (SkiaSharp.SKPoint c, float radius, SkiaSharp.SKPaint paint);

我想延迟画圆圈。我已经阅读了所有关于 C# xamarian 动画的文档,但无法找到一个简单的解决方案。

https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/simple https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/graphics-and-animation https://learn.microsoft.com/en-us/dotnet/api/xamarin.forms.animation?view=xamarin-forms .

以上内容中没有关于这个问题的内容。

谁能告诉我从哪里开始延迟绘制两个对象的提示?

public class SimpleCirclePage : ContentPage
{
public SimpleCirclePage()
{
SKCanvasView canvasView = new SKCanvasView();
canvasView.PaintSurface += OnCanvasViewPaintSurface;
Content = canvasView;
}

void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
{
SKImageInfo info = args.Info;
SKSurface surface = args.Surface;
SKCanvas canvas = surface.Canvas;

canvas.Clear();

SKPaint paint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = Color.Red.ToSKColor(),
StrokeWidth = 10
};
canvas.DrawCircle(info.Width / 3, info.Height / 2, 100, paint);
// I want to draw the second circle after some delay.
canvas.DrawCircle(info.Width / 3, info.Height / 3, 100, paint);
}
}

最佳答案

您可以将第二个圆默认半径设置为0,这样就不会在页面上绘制了。然后经过一些延迟(我在这里设置了 4000ms),你可以将 radius 设置为 100 并重绘 View ,第二个将出现。这是你想要的吗?

public class SimpleCirclePage : ContentPage{

float radius = 0;

public SimpleCirclePage()
{
SKCanvasView canvasView = new SKCanvasView();
canvasView.PaintSurface += OnCanvasViewPaintSurface;
this.Content = canvasView;

Device.StartTimer(TimeSpan.FromMilliseconds(4000), () =>
{
radius= 100;
canvasView.InvalidateSurface();

return false;
});
}

void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
{
SKImageInfo info = args.Info;
SKSurface surface = args.Surface;
SKCanvas canvas = surface.Canvas;

canvas.Clear();

SKPaint paint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = Color.Red.ToSKColor(),
StrokeWidth = 10
};

canvas.DrawCircle(info.Width / 3, info.Height / 2, 100, paint);

// I want to draw the second circle after some delay.
canvas.DrawCircle(info.Width / 3, info.Height / 3, radius, paint);
}
}

您可以阅读文档:skiasharp/basics/animation

关于c# - 如何使用 SkiaSharp 在 Xamarin 中创建简单的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59533643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com