/gist:7d4bc2e3558fe66eceea Secret
Created
May 30, 2014 20:38
Star
You must be signed in to star a gist
Xamarin.Forms Easing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Xamarin.Forms; | |
namespace XamFormsEasing | |
{ | |
public class App | |
{ | |
public static Page GetMainPage () | |
{ | |
var b = new Button { | |
Text = "Click me", | |
VerticalOptions = LayoutOptions.CenterAndExpand, | |
HorizontalOptions = LayoutOptions.CenterAndExpand, | |
}; | |
var v = new BoxView { | |
BackgroundColor = Color.Green | |
}; | |
var sl = new AbsoluteLayout { | |
Children = { b, v } | |
}; | |
AbsoluteLayout.SetLayoutBounds(sl.Children[0], | |
new Rectangle(20, 20, | |
AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); | |
AbsoluteLayout.SetLayoutBounds(sl.Children[1], | |
new Rectangle(20, 80, | |
AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize)); | |
int iClicks = 0; | |
var eAndN = new Tuple<Easing,string>[] { | |
new Tuple<Easing, string> (Easing.BounceIn, "BounceIn"), | |
new Tuple<Easing, string> (Easing.BounceOut, "BounceOut"), | |
new Tuple<Easing, string> (Easing.CubicIn, "CubicInOut"), | |
new Tuple<Easing, string> (Easing.CubicOut, "CubicOut"), | |
new Tuple<Easing, string> (Easing.Linear, "Linear"), | |
new Tuple<Easing, string> (Easing.SinIn, "SinIn"), | |
new Tuple<Easing, string> (Easing.SinInOut, "SinInOut"), | |
new Tuple<Easing, string> (Easing.SinOut, "SinOut"), | |
new Tuple<Easing, string> (Easing.SpringIn, "SpringIn"), | |
new Tuple<Easing, string> (Easing.SpringOut, "SpringOut"), | |
new Tuple<Easing, string> (new Easing(Math.Sin), "Custom") | |
}; | |
b.Clicked += (object sender, EventArgs e) => { | |
var newPos = new Rectangle(240, 80, 20, 20); | |
var eAndName = eAndN[iClicks]; | |
var easing = eAndName.Item1; | |
b.Text = eAndName.Item2; | |
v.LayoutTo ( newPos, 2500, easing); | |
iClicks++; | |
iClicks %= eAndN.Length; | |
}; | |
var cp = new ContentPage { | |
Content = sl | |
}; | |
return cp; | |
} | |
} | |
} | |
I have few problems that I could not succeed to solve.
The first one was to render the BoxView:
I coul not succeed to see it, even using other layouts.
If I use another button and animate that, then it works.
But then I have another problem:
it works only the first time, then not anymore.
Any idea?
Oké, I have found the problem, at least for the animation executing only once. Obviously, it was in my code :)
I was using the RotateTo method, which is then setting the property of the object to the given angle, so when we call this again, the angle is already set and there is no movement.
The best solution in this case is than:
myFancyView.RotateTo ( myFancyView.Rotation + angle, duration, easing );
which will then use the actual angle of the view.
By the way I still cannot see the BoxView...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What about Custom one?