Created
August 24, 2013 18:23
-
-
Save davidortinau/6329630 to your computer and use it in GitHub Desktop.
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
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 | |
}; |
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
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