问题
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