如何在 Xamarin Forms 上创建和重复动画 [英] How to create and repeat a Animation on Xamarin Forms

查看:28
本文介绍了如何在 Xamarin Forms 上创建和重复动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重复我的动画,我想要的是我的按钮从屏幕中间的宽度边缘移动并返回到另一个宽度边缘,到目前为止我得到了这个.

I'm trying to repeat my animation, what i want is to my button goes from the middle of screen at the width edge and return to the other width edge, so far I got this.

var exitRight = new Animation(callback: d => lab.TranslationX = d,
                                       start: 0,
                                       end: width,
                                       easing: Easing.Linear);

        var enterLeft = new Animation(callback: d => lab.TranslationX = d,
                                       start: width,
                                       end: -width,
                                       easing: Easing.Linear);

        storyboard.Add(0, 0.5, exitRight);
        storyboard.Add(0.5, 1, enterLeft);

        storyboard.Commit(lab, "lab", length: 5000,repeat:()=> true);

问题是它不返回,它穿过屏幕并从另一侧返回,即使我通过 Func 参数也不会重复.

The problem is it doesn't return, it cross the screen and return from the other side and it doesn't repeat even if i pass the Func Paramenter.

推荐答案

摘自 这里!

运行使用 Animation 类创建的动画(可能包含也可能不包含子动画)是通过调用 Commit 方法实现的.此方法指定动画的持续时间,以及控制是否重复动画的回调.

Running an animation created with the Animation class, which may or may not include child animations, is achieved by calling the Commit method. This method specifies the duration of the animation, and amongst other items, a callback that controls whether to repeat the animation.

稍后发布:

Commit 方法中指定了以下参数:[...]- 第七个参数(repeat)是一个回调,允许重复动画.在动画结束时调用,返回true表示动画应该重复.

The following arguments are specified in the Commit method: [...] - The seventh argument (repeat) is a callback that allows the animation to be repeated. It's called at the end of the animation, and returning true indicates that the animation should be repeated.

为了让您的示例工作,我猜您确实需要所有 7 参数.

To get your example working I guess you really need the all of the 7 parameters.

希望它能以某种方式帮助你!

Hope it helps you somehow !

这篇关于如何在 Xamarin Forms 上创建和重复动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆