Reputation: 2904
I am trying to animate a range transition in Xamarin, but I am having some problems:
public void SetXRange(float range){
CPTXYPlotSpace space = graph.DefaultPlotSpace as CPTXYPlotSpace;
CPTPlotRange xRange = new CPTPlotRange ((NSDecimal)range, (NSDecimal)range);
CPTAnimation.Animate (
NSObject.FromObject (space),
"XRange",
new CPTAnimationPeriod (space.XRange, xRange, 2f, 0f),
CPTAnimationCurve.Linear,
new CPTAnimationDelegate());
}
That causes the error described here: Failed to create an instance of the native type 'NSObject'.
However the same solution doesn´t apply, because if I set the delegate to null
I get another error:
"System.ArgumentNullException has been thrown. Argument cannot be null. Parameter name: animationDelegate"
Even when I try creating a delegate and setting, MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure = false;
i don´t get an animation, I just avoid the error.
Has anybody got a working CorePlot animation with Xamarin?
Upvotes: 0
Views: 265
Reputation: 1299
make sure you implement the CPTAnimationDelegate. Like:
public class CptDelegate : CPTAnimationDelegate
{
public override void AnimationCancelled (CPTAnimationOperation operation)
{
}
public override void AnimationDidFinish (CPTAnimationOperation operation)
{
}
public override void AnimationDidStart (CPTAnimationOperation operation)
{
}
public override void AnimationDidUpdate (CPTAnimationOperation operation)
{
}
public override void AnimationWillUpdate (CPTAnimationOperation operation)
{
}
}
Then create the animation the other way round, you animate from actual range to your minimal range. So it should be more like this (taken from my appcode and works fine):
space.XRange = new CPTPlotRange (new NSDecimalNumber (newXMin.ToString ()).NSDecimalValue,
new NSDecimalNumber (newXMax.ToString ()).NSDecimalValue);
var startRange = new CPTPlotRange (new NSDecimalNumber (0.ToString ()).NSDecimalValue,
new NSDecimalNumber (0.ToString ()).NSDecimalValue);
cptDelegate = new CptDelegate ();
CPTAnimation.Animate (space, "XRange", new CPTAnimationPeriod (startRange, space.XRange, 2f, 0f), CPTAnimationCurve.Linear,
cptDelegate);
Upvotes: 0