Skip to content

Instantly share code, notes, and snippets.

@Teness
Forked from aloisdeniel/Animation Fade
Last active September 17, 2015 05:28
Show Gist options
  • Select an option

  • Save Teness/2c428c65931a2d1b0bf8 to your computer and use it in GitHub Desktop.

Select an option

Save Teness/2c428c65931a2d1b0bf8 to your computer and use it in GitHub Desktop.

Revisions

  1. @aloisdeniel aloisdeniel revised this gist Feb 18, 2015. No changes.
  2. @aloisdeniel aloisdeniel revised this gist Feb 18, 2015. 1 changed file with 28 additions and 0 deletions.
    28 changes: 28 additions & 0 deletions Xamarin.iOS Animations
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    //Some examples from below animation gists

    this.view = new UIView (new CGRect (50, 50, 70, 100));
    this.view.BackgroundColor = UIColor.Red;
    this.View.AddSubview (this.view);

    this.animations = new Dictionary<string, Action> () {
    { "FadeIn", () => view.Fade (true) },
    { "FadeOut", () => view.Fade (false) },
    { "RotateIn", () => view.Rotate (true) },
    { "RotateOut", () => view.Rotate (false) },
    { "FlipInVerticaly", () => view.FlipVerticaly (true) },
    { "FlipOutVerticaly", () => view.FlipVerticaly (false) },
    { "FlipInHorizontaly", () => view.FlipHorizontaly (true) },
    { "FlipOutHorizontaly", () => view.FlipHorizontaly (false) },
    { "SlideInFromTop", () => view.SlideVerticaly (true, true) },
    { "SlideInFromBottom", () => view.SlideVerticaly (true, false) },
    { "SlideInFromLeft", () => view.SlideHorizontaly (true, true) },
    { "SlideInFromRight", () => view.SlideHorizontaly (true, false) },
    { "SlideOutFromTop", () => view.SlideVerticaly (false, true) },
    { "SlideOutFromBottom", () => view.SlideVerticaly (false, false) },
    { "SlideOutFromLeft", () => view.SlideHorizontaly (false, true) },
    { "SlideOutFromRight", () => view.SlideHorizontaly (false, false) },
    { "ZoomIn", () => view.Zoom (true) },
    { "ZoomOut", () => view.Zoom (false) },
    { "ScaleIn", () => view.Scale (true) },
    { "ScaleOut", () => view.Scale (false) },
    };
  3. @aloisdeniel aloisdeniel revised this gist Feb 18, 2015. 8 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  4. @aloisdeniel aloisdeniel created this gist Feb 18, 2015.
    14 changes: 14 additions & 0 deletions Fade
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    public static void Fade (this UIView view, bool isIn, double duration = 0.3, Action onFinished = null)
    {
    var minAlpha = (nfloat)0.0f;
    var maxAlpha = (nfloat)1.0f;

    view.Alpha = isIn ? minAlpha : maxAlpha;
    view.Transform = CGAffineTransform.MakeIdentity ();
    UIView.Animate (duration, 0, UIViewAnimationOptions.CurveEaseInOut,
    () => {
    view.Alpha = isIn ? maxAlpha : minAlpha;
    },
    onFinished
    );
    }
    26 changes: 26 additions & 0 deletions Flip horizontaly
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    public static void FlipHorizontaly (this UIView view, bool isIn, double duration = 0.3, Action onFinished = null)
    {
    var m34 = (nfloat)(-1 * 0.001);

    var minAlpha = (nfloat)0.0f;
    var maxAlpha = (nfloat)1.0f;

    view.Alpha = (nfloat)1.0;

    var minTransform = CATransform3D.Identity;
    minTransform.m34 = m34;
    minTransform = minTransform.Rotate ((nfloat)((isIn ? 1 : -1) * Math.PI * 0.5), (nfloat)0.0f, (nfloat)1.0f, (nfloat)0.0f);
    var maxTransform = CATransform3D.Identity;
    maxTransform.m34 = m34;

    view.Alpha = isIn ? minAlpha : maxAlpha;
    view.Layer.Transform = isIn ? minTransform : maxTransform;
    UIView.Animate (duration, 0, UIViewAnimationOptions.CurveEaseInOut,
    () => {
    view.Layer.AnchorPoint = new CGPoint ((nfloat)0.5, (nfloat)0.5f);
    view.Layer.Transform = isIn ? maxTransform : minTransform;
    view.Alpha = isIn ? maxAlpha : minAlpha;
    },
    onFinished
    );
    }
    24 changes: 24 additions & 0 deletions Flip verticaly
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    public static void FlipVerticaly (this UIView view, bool isIn, double duration = 0.3, Action onFinished = null)
    {
    var m34 = (nfloat)(-1 * 0.001);

    var minAlpha = (nfloat)0.0f;
    var maxAlpha = (nfloat)1.0f;

    var minTransform = CATransform3D.Identity;
    minTransform.m34 = m34;
    minTransform = minTransform.Rotate ((nfloat)((isIn ? 1 : -1) * Math.PI * 0.5), (nfloat)1.0f, (nfloat)0.0f, (nfloat)0.0f);
    var maxTransform = CATransform3D.Identity;
    maxTransform.m34 = m34;

    view.Alpha = isIn ? minAlpha : maxAlpha;
    view.Layer.Transform = isIn ? minTransform : maxTransform;
    UIView.Animate (duration, 0, UIViewAnimationOptions.CurveEaseInOut,
    () => {
    view.Layer.AnchorPoint = new CGPoint ((nfloat)0.5, (nfloat)0.5f);
    view.Layer.Transform = isIn ? maxTransform : minTransform;
    view.Alpha = isIn ? maxAlpha : minAlpha;
    },
    onFinished
    );
    }
    17 changes: 17 additions & 0 deletions Rotate
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    public static void Rotate (this UIView view, bool isIn, bool fromLeft = true, double duration = 0.3, Action onFinished = null)
    {
    var minAlpha = (nfloat)0.0f;
    var maxAlpha = (nfloat)1.0f;
    var minTransform = CGAffineTransform.MakeRotation ((nfloat)((fromLeft ? -1 : 1) * 720));
    var maxTransform = CGAffineTransform.MakeRotation ((nfloat)0.0);

    view.Alpha = isIn ? minAlpha : maxAlpha;
    view.Transform = isIn ? minTransform : maxTransform;
    UIView.Animate (duration, 0, UIViewAnimationOptions.CurveEaseInOut,
    () => {
    view.Alpha = isIn ? maxAlpha : minAlpha;
    view.Transform = isIn ? maxTransform : minTransform;
    },
    onFinished
    );
    }
    17 changes: 17 additions & 0 deletions Scale
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    public static void Scale (this UIView view, bool isIn, double duration = 0.3, Action onFinished = null)
    {
    var minAlpha = (nfloat)0.0f;
    var maxAlpha = (nfloat)1.0f;
    var minTransform = CGAffineTransform.MakeScale ((nfloat)0.1, (nfloat)0.1);
    var maxTransform = CGAffineTransform.MakeScale ((nfloat)1, (nfloat)1);

    view.Alpha = isIn ? minAlpha : maxAlpha;
    view.Transform = isIn ? minTransform : maxTransform;
    UIView.Animate (duration, 0, UIViewAnimationOptions.CurveEaseInOut,
    () => {
    view.Alpha = isIn ? maxAlpha : minAlpha;
    view.Transform = isIn ? maxTransform : minTransform;
    },
    onFinished
    );
    }
    17 changes: 17 additions & 0 deletions Slide horizontaly
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    public static void SlideHorizontaly (this UIView view, bool isIn, bool fromLeft, double duration = 0.3, Action onFinished = null)
    {
    var minAlpha = (nfloat)0.0f;
    var maxAlpha = (nfloat)1.0f;
    var minTransform = CGAffineTransform.MakeTranslation ((fromLeft ? -1 : 1) * view.Bounds.Width, 0);
    var maxTransform = CGAffineTransform.MakeIdentity ();

    view.Alpha = isIn ? minAlpha : maxAlpha;
    view.Transform = isIn ? minTransform : maxTransform;
    UIView.Animate (duration, 0, UIViewAnimationOptions.CurveEaseInOut,
    () => {
    view.Alpha = isIn ? maxAlpha : minAlpha;
    view.Transform = isIn ? maxTransform : minTransform;
    },
    onFinished
    );
    }
    17 changes: 17 additions & 0 deletions Slide verticaly
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    public static void SlideVerticaly (this UIView view, bool isIn, bool fromTop, double duration = 0.3, Action onFinished = null)
    {
    var minAlpha = (nfloat)0.0f;
    var maxAlpha = (nfloat)1.0f;
    var minTransform = CGAffineTransform.MakeTranslation (0, (fromTop ? -1 : 1) * view.Bounds.Height);
    var maxTransform = CGAffineTransform.MakeIdentity ();

    view.Alpha = isIn ? minAlpha : maxAlpha;
    view.Transform = isIn ? minTransform : maxTransform;
    UIView.Animate (duration, 0, UIViewAnimationOptions.CurveEaseInOut,
    () => {
    view.Alpha = isIn ? maxAlpha : minAlpha;
    view.Transform = isIn ? maxTransform : minTransform;
    },
    onFinished
    );
    }
    17 changes: 17 additions & 0 deletions Zoom
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    public static void Zoom (this UIView view, bool isIn, double duration = 0.3, Action onFinished = null)
    {
    var minAlpha = (nfloat)0.0f;
    var maxAlpha = (nfloat)1.0f;
    var minTransform = CGAffineTransform.MakeScale ((nfloat)2.0, (nfloat)2.0);
    var maxTransform = CGAffineTransform.MakeScale ((nfloat)1, (nfloat)1);

    view.Alpha = isIn ? minAlpha : maxAlpha;
    view.Transform = isIn ? minTransform : maxTransform;
    UIView.Animate (duration, 0, UIViewAnimationOptions.CurveEaseInOut,
    () => {
    view.Alpha = isIn ? maxAlpha : minAlpha;
    view.Transform = isIn ? maxTransform : minTransform;
    },
    onFinished
    );
    }