Created
September 18, 2015 07:24
-
-
Save programmation/7408f2888a9c51a0d58f to your computer and use it in GitHub Desktop.
Xamarin Forms View extension (shake)
This file contains hidden or 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
public static void Shake (this View view, int shakes = 4, Action completion = null) | |
{ | |
Task.Run (() => { | |
Device.BeginInvokeOnMainThread (async () => { | |
uint duration = 50; | |
await view.TranslateTo (5.0, 0, duration, Easing.Linear); | |
for (var shake = 1; shake < shakes - 1; shake++) { | |
await view.TranslateTo (-10.0, 0, duration, Easing.Linear); | |
await view.TranslateTo (10.0, 0, duration, Easing.Linear); | |
} | |
await view.TranslateTo (0, 0, duration, Easing.Linear); | |
if (completion != null) { | |
completion (); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment