我试图在Xamarin中设置范围转换的动画,但我遇到了一些问题:
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());
}
这会导致此处描述的错误:Failed to create an instance of the native type 'NSObject'。
但是同样的解决方案不适用,因为如果我将委托设置为null
,我会收到另一个错误:
“抛出了System.ArgumentNullException。参数不能为null。参数名称:animationDelegate”
即使我尝试创建委托和设置,MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure = false;
我也没有动画,我只是避免错误。
有没有人使用Xamarin获得有效的CorePlot动画?
答案 0 :(得分:0)
确保您实施CPTAnimationDelegate。像:
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)
{
}
}
然后以相反的方式创建动画,您可以从实际范围动画到最小范围。所以它应该更像这样(取自我的appcode并且工作正常):
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);