我想创建一个按下图标时触发的动画
我如何在遵循MVVM模式的同时完成它。
查看
<Image Source="ic_test.png" HorizontalOptions="Center" VerticalOptions="Start" Margin="16,24,16,0">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding AnimationTestCommand}" />
</Image.GestureRecognizers>
</Image>
答案 0 :(得分:2)
您需要创建一个自定义图像并将动画放在下方,如下所示:
public class CustomImage : Image
{
public CustomImage() : base()
{
const int _animationTime = 10;
var iconTap = new TapGestureRecognizer();
iconTap.Tapped += async (sender, e) =>
{
try
{
var btn = (CustomImage)sender;
await btn.ScaleTo(5, _animationTime);
//await btn.ScaleTo(1, _animationTime);
}
catch (Exception ex)
{
ex.Track();
}
};
}
}