【问题标题】:CorePlot animations in XamarinXamarin 中的 CorePlot 动画
【发布时间】:2014-03-03 13:43:37
【问题描述】:

我正在尝试在 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。参数不能为空。参数名称:animationDelegate”

即使我尝试创建委托和设置,MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure = false; 我也没有得到动画,我只是避免了错误。

有没有人用 Xamarin 制作了一个正常工作的 CorePlot 动画?

【问题讨论】:

  • 我不会将此作为答案,因为我不知道 Core Plot 并且无法尝试我的解决方案,但我建议您使用 do- 实现 MyCPTAnimationDelegate : CPTAnimationDelegate没有任何方法,实例化那个 (myDelegate = new MyCPTAnimationDelegate()) 的实例并传递那个对象。
  • 它不会抛出异常,但它什么也不做。我已经尝试过类似的实现 ICPTAnimationDelegate 并且发生了同样的事情。

标签: c# xamarin.ios xamarin core-plot


【解决方案1】:

确保您实现了 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)
    {
    }
}

然后反过来创建动画,从实际范围到最小范围进行动画处理。所以它应该更像这样(取自我的应用程序代码并且工作正常):

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多