Created
October 17, 2016 15:19
-
-
Save jorwan/1ed57459c7b01b5a5b1135219e6219cf to your computer and use it in GitHub Desktop.
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 class UtilAnimation | |
{ | |
/// <summary> | |
/// Shakes it. | |
/// </summary> | |
/// <param name="view">View.</param> | |
/// <param name="Duration">Duration.</param> | |
/// <param name="RepeatCount">Repeat count.</param> | |
/// <param name="MovementDistance">Movement distance.</param> | |
/// <param name="AnimationKey">Animation key.</param> | |
public static void ShakeIt(this UIView view, float Duration = 0.05f, int RepeatCount = 8, float MovementDistance = 20f, string AnimationKey = "position") | |
{ | |
CABasicAnimation animation = new CABasicAnimation(); | |
animation.Duration = Duration; | |
animation.RepeatCount = RepeatCount; | |
animation.AutoReverses = true; | |
animation.SetFrom(NSValue.FromCGPoint(new CGPoint(view.Center.X-MovementDistance, view.Center.Y-MovementDistance))); | |
animation.SetTo(NSValue.FromCGPoint(new CGPoint(view.Center.X+MovementDistance, view.Center.Y+MovementDistance))); | |
view.Layer.AddAnimation(animation, AnimationKey); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of Use: