我只是使用 SkiaSharp 在毛伊岛硬编码动画,当我运行应用程序时,动画不会显示。它确实占用了我设置的空间量,但它不显示任何内容。
XAML代码
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WeatherApplication.MainPage"
xmlns:model="clr-namespace:WeatherApplication.Model"
xmlns:viewmodel="clr-namespace:WeatherApplication.ViewModel"
xmlns:skia="clr-namespace:SkiaSharp.Extended.UI.Controls;assembly=SkiaSharp.Extended.UI"
x:DataType="viewmodel:YourCurrentLocationForecast"
Title="{Binding Title}">
<VerticalStackLayout>
<skia:SKLottieView Source="Resources/Raw/sunny.json"
RepeatCount="-1" HeightRequest="200" WidthRequest="100" />
<Button BackgroundColor="Yellow"/>
</VerticalStackLayout>
</ContentPage>
使用 UseSkiaSharp() 方法的 mauiprogram.cs 代码
using SkiaSharp.Views.Maui.Controls.Hosting;
namespace WeatherApplication;
public static class MauiProgram
{
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>().UseSkiaSharp()
.ConfigureFonts(fonts =>
{
fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
});
builder.Services.AddSingleton<IConnectivity>(Connectivity.Current);
builder.Services.AddSingleton<IGeolocation>(Geolocation.Default);
builder.Services.AddSingleton<IMap>(Map.Default);
builder.Services.AddSingleton<MainPage>();
builder.Services.AddSingleton<YourCurrentLocationForecast>();
builder.Services.AddSingleton<WeatherService>();
return builder.Build();
}
}
无论我使用什么版本,它仍然不显示任何内容。我尝试使用nuget网站上的cli,也尝试过vs for mac,就像这里一样:https://cedricgabrang.medium.com/implementing-lottie-animations-in-your-net-maui-application-62bd484af651
我将.NET8与SkiaSharp.Extended.UI.Maui(版本=“2.0.0-preview.86”)一起使用
我将json文件放在Resource/Raw文件夹中,
我设置了主页,
public partial class App : Application
{
public App(MainPage mainPage)
{
InitializeComponent();
MainPage = new NavigationPage(mainPage);
}
}
当然我在MauiProgram中注册了MainPage,
builder.Services.AddSingleton<MainPage>();
在 MainPage.xaml 中,我使用几乎相同的代码,
<VerticalStackLayout>
<skia:SKLottieView Source="dotnetbot.json"
RepeatCount="-1" HeightRequest="200" WidthRequest="100" />
<Button BackgroundColor="Yellow"/>
</VerticalStackLayout>
针对 iPad Pro iOS17.2,