Xamarin表单登录按钮动画
我已经用XAML创建了一个类似于gif格式的登录页面。现在我想像示例中那样设置按钮的动画。我从来没有用Xamarin的形式制作过任何动画,所以我不知道如何实现这样的过渡。有人能解释一下我怎样才能让按钮缩小成一个圆圈,变成一个正在加载的动画吗 该按钮当前看起来如下所示:Xamarin表单登录按钮动画,xamarin,animation,login,xamarin.forms,lottie,Xamarin,Animation,Login,Xamarin.forms,Lottie,我已经用XAML创建了一个类似于gif格式的登录页面。现在我想像示例中那样设置按钮的动画。我从来没有用Xamarin的形式制作过任何动画,所以我不知道如何实现这样的过渡。有人能解释一下我怎样才能让按钮缩小成一个圆圈,变成一个正在加载的动画吗 该按钮当前看起来如下所示: <Button Text="Login" Style="{StaticResource LoginFormButton}" /> <!-- LoginFormButton is defined in App.x
<Button Text="Login" Style="{StaticResource LoginFormButton}" />
<!-- LoginFormButton is defined in App.xaml -->
<Style x:Key="LoginFormButton" TargetType="Button">
<Setter Property="FontSize" Value="18" />
<Setter Property="TextColor" Value="{ StaticResource bgColor }" />
<Setter Property="BorderRadius" Value="25" />
<Setter Property="BackgroundColor" Value="White" />
</Style>
据我所知,在Xamarin表单中,只需一个按钮是无法做到这一点的。 这将需要更多的元素添加到页面中。然后,可以使用Xamarin的内置动画系统来调整元素的尺寸,并在动画过程中激活/禁用其IsVisible属性 但是,我会这样做:
还要确保网格的IsClippedToBounds属性设置为false,否则圆视图将无法超出其包含的网格。我相信使用Xamanimation可以做到这一点,我不确定这是否是最好的方法。另一种可能性是使用动画,我推荐洛蒂 如果您要使用Xamanimation
xmlns:xamanimation="clr-namespace:Xamanimation;assembly=Xamanimation"
<ContentPage.Resources>
<ResourceDictionary>
<xamanimation:StoryBoard x:Key="Animation1"
Target="{x:Reference Button1}">
<xamanimation:FadeToAnimation Opacity="1" Duration="1500" Easing="Linear"/>
<xamanimation:FadeToAnimation Opacity="0" Duration="1500" Easing="Linear"/>
</xamanimation:StoryBoard>
<xamanimation:StoryBoard x:Key="Animation2"
Target="{x:Reference Button1}">
<xamanimation:FadeToAnimation Opacity="1" Delay="3000" Duration="1500" Easing="Linear"/>
<xamanimation:FadeToAnimation Opacity="0" Duration="1500" Easing="Linear"/>
</xamanimation:StoryBoard>
</ResourceDictionary>
</ContentPage.Resources>
或者你可以用洛蒂
您不能直接在Xamarin表单中制作此类动画,您必须以本机方式制作!检查此链接类似的按钮动画是否存在,您可以使用此链接。我来看看。谢谢你的回答!
<Button x:Name="Button1"
Opacity="0"/>
protected override void OnAppearing()
{
if (Resources["Animation1"] is StoryBoard storyBoardText1)
storyBoardText1.Begin();
if (Resources["Animation2"] is StoryBoard storyBoardText2)
storyBoardText2.Begin();
base.OnAppearing();
}