How to animate opacity in Xamarin.Forms

拈花ヽ惹草 提交于 2019-12-10 10:38:54

问题


I wonder how to Animate opacity of elements visible on screen. For example for Entry I got to this:

this.Animate("", d =>
{
   Debug.WriteLine("anim:" + d);
   Username.Opacity = (AnimationTime - d) / AnimationTime;
}, 0, AnimationTime);

but I wonder if there is easier way. Unfortunately Animate method is poorly documented.


回答1:


You could try the FadeTo extension method :-

http://iosapi.xamarin.com/index.aspx?link=M%3AXamarin.Forms.ViewExtensions.FadeTo%28Xamarin.Forms.VisualElement%2CSystem.Double%2CSystem.UInt32%2CXamarin.Forms.Easing%29

There are other animations that can be applied too :-

http://iosapi.xamarin.com/index.aspx?link=T%3AXamarin.Forms.ViewExtensions%2F*

You may also find the following a useful reference :-

http://www.xforms-kickstarter.com/#animations-putting-your-app-into-motion




回答2:


Use the YourLabel.FadeTo() method. For example, if you define the opacity to 0 starting the app,

await MyLabel.FadeTo (1, 2000, Easing.Linear);

means : the animation (changing opacity here) will last for 2000 ms linearly passing from 0 to 1.



来源:https://stackoverflow.com/questions/27985759/how-to-animate-opacity-in-xamarin-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!