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

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

问题描述

我正在尝试重复我的动画,我想要的按钮是从屏幕中间的宽度边缘开始,然后返回另一个宽度边缘,到目前为止,我明白了.

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 Paramenter也不会重复.

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方法实现的.此方法指定动画的持续时间,以及其他项,控制是否重复播放动画的回调.

最新信息:

在Commit方法中指定了以下参数: [...] -第七个参数(重复)是允许重复播放动画的回调.在动画结束时调用它,并返回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表单上创建和重复动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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