代码之家  ›  专栏  ›  技术社区  ›  napi15

请求异步任务时是否可以弹出lottie动画视图?

  •  0
  • napi15  · 技术社区  · 6 年前

    我创建了一个内容视图,在这个内容视图中,我插入了一个lottie动画:

    我正在尝试将其设置为通用动画视图,以便可以将其用于多个异步任务。

    加载动画.xaml

    <?xml version="1.0" encoding="UTF-8"?>
    <ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:lottie="clr-namespace:Lottie.Forms;assembly=Lottie.Forms"
                 x:Class="Fit_Plans.Views.Common.LoadingAnimation">
      <ContentView.Content>
          <StackLayout>
              <lottie:AnimationView
                  Grid.Column="0"
                  Margin="-20"
                  x:Name="LoadingAnimationView"
                  Animation="loading_animation.json"
    
                  AutoPlay="false"
                  HeightRequest="160"
                  WidthRequest="160"
                  VerticalOptions="FillAndExpand"
                  HorizontalOptions="FillAndExpand"/>
            </StackLayout>
      </ContentView.Content>
    </ContentView>
    

    现在在my someview.xaml.cs中

     async protected override void OnAppearing()
            {
                Product produits = new Product();          
                if(getListProduit ==null || getListProduit.Count<=0)
                {  
                    getListProduit = await produits.loadMenuAsync(api, siteUrl);
                    PopulateProductsLists(getListProduit);
                }
                base.OnAppearing();
    
            }
    

    您可以注意到我有一个等待异步任务:

    getListProduit = await produits.loadMenuAsync(api, siteUrl);
    

    是否可以让我的lottie动画弹出animation.jason,当任务完成时关闭弹出窗口?或者,做这种事最好的方法是什么?

    1 回复  |  直到 6 年前
        1
  •  2
  •   Michał Å»ołnieruk    6 年前

    Rg.Plugins.Popup

    <pages:PopupPage 
        xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:pages="clr-namespace:Rg.Plugins.Popup.Pages;assembly=Rg.Plugins.Popup"
        xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"
        x:Class="MyProject.MyPopupPage">
        <!--You can set an animation in the xaml file or in the csharp code behind-->
        <pages:PopupPage.Animation>
            <animations:ScaleAnimation 
                PositionIn="Center"
                PositionOut="Center"
                ScaleIn="1.2"
                ScaleOut="0.8"
                DurationIn="400"
                DurationOut="300"
                EasingIn="SinOut"
                EasingOut="SinIn"
                HasBackgroundAnimation="True"/>
        </pages:PopupPage.Animation>
        <!--You can use any elements here which are extended from Xamarin.Forms.View-->
         <lottie:AnimationView
              Grid.Column="0"
              Margin="-20"
              x:Name="LoadingAnimationView"
              Animation="loading_animation.json"
    
              AutoPlay="true"
              HeightRequest="160"
              WidthRequest="160"
              VerticalOptions="FillAndExpand"
              HorizontalOptions="FillAndExpand"/>
    </pages:PopupPage>
    

    Here