Last active
October 2, 2017 21:04
-
-
Save lothrop/8186857 to your computer and use it in GitHub Desktop.
Xamarin.iOS shake animation
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
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