Skip to content

Instantly share code, notes, and snippets.

@lothrop
Last active October 2, 2017 21:04
Show Gist options
  • Save lothrop/8186857 to your computer and use it in GitHub Desktop.
Save lothrop/8186857 to your computer and use it in GitHub Desktop.
Xamarin.iOS shake animation
public static async Task AnimateShakeAsync(UIView view)
{
await AnimateHorizontalMovementAsync(view, -10);
await AnimateHorizontalMovementAsync(view, 20);
await AnimateHorizontalMovementAsync(view, -20);
await AnimateHorizontalMovementAsync(view, 20);
await AnimateHorizontalMovementAsync(view, -15);
await AnimateHorizontalMovementAsync(view, 10);
await AnimateHorizontalMovementAsync(view, -5);
}
private static async Task AnimateHorizontalMovementAsync(UIView view, nfloat horizontalOffset)
{
await UIView.AnimateAsync(0.065, () => view.Frame =
new CGRect(new CGPoint(view.Frame.Left + horizontalOffset, view.Frame.Top),
view.Frame.Size));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment