Skip to content

Instantly share code, notes, and snippets.

@davidortinau
Created August 24, 2013 18:23
Show Gist options
  • Save davidortinau/6329630 to your computer and use it in GitHub Desktop.
Save davidortinau/6329630 to your computer and use it in GitHub Desktop.
var localMediaTime = CAAnimation.CurrentMediaTime();
NSObject[] keyframes = TweenBuilder.CreateKeyValues(-295, 0, Easing.EaseOutBounce);
var homeIn = new CAKeyFrameAnimation {
KeyPath = "position.x",
Duration = 1.4,
BeginTime = localMediaTime,
FillMode = CAFillMode.Forwards,
RemovedOnCompletion = false,
TimingFunction = CAMediaTimingFunction.FromName( CAMediaTimingFunction.Linear ),
Values = keyframes
};
using System;
using MonoTouch.Foundation;
namespace Example_CoreAnimation
{
public delegate float EasingFormula(float t, float start, float length);
public class TweenBuilder
{
public static NSObject[] CreateKeyValues (float fromValue, float toValue, EasingFormula easingFormula, int steps = 100)
{
NSObject[] values = new NSObject[steps];
double value = 0;
float curTime = 0;
for (int t = 0; t < steps; t++) {
curTime = (float)t / (float)steps;
var easingFactor = easingFormula(curTime, 0, 1);
value = (toValue - fromValue) * easingFactor + fromValue;
values[t] = NSNumber.FromDouble(value);
}
return values;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment