Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在xamarin.ios中暂停CAAnimation_C#_Ios_Xamarin_Xamarin.ios_Caanimation - Fatal编程技术网

C# 如何在xamarin.ios中暂停CAAnimation

C# 如何在xamarin.ios中暂停CAAnimation,c#,ios,xamarin,xamarin.ios,caanimation,C#,Ios,Xamarin,Xamarin.ios,Caanimation,我正试图在xamarin.ios项目中制作一个圆圈的动画,下面是我的代码,所有的东西都在工作,但除了暂停,当我点击暂停时,它会在大约3秒钟后暂停(即它制作了一段时间的圆圈动画,然后它停止),它不准确,我如何解决这个问题,非常感谢任何帮助 // create the dial private CAShapeLayer createDial (UIColor color,CAShapeLayer circle,UIView parent,float strokeEnd)

我正试图在xamarin.ios项目中制作一个圆圈的动画,下面是我的代码,所有的东西都在工作,但除了暂停,当我点击暂停时,它会在大约3秒钟后暂停(即它制作了一段时间的圆圈动画,然后它停止),它不准确,我如何解决这个问题,非常感谢任何帮助

// create the dial
        private CAShapeLayer createDial (UIColor color,CAShapeLayer circle,UIView parent,float strokeEnd)
        {
            // Create the circle using CAShapeLayer
            int radius = (int) this.View.Frame.Width/2 -20;
            circle = new CAShapeLayer ();
            circle.Path = UIBezierPath.FromRoundedRect (new CGRect (0, 0, 2.0 * radius, 2.0 * radius), radius).CGPath;
            //circle.Path = UIBezierPath.FromArc ( new CGPoint (((this.View.Frame.Width / 2) - radius), ((this.View.Frame.Height / 2) - radius)), radius, 0, 360, true).CGPath;
            circle.Position = new CGPoint (((parent.Frame.Width / 2) - radius), ((parent.Frame.Height / 2) - radius));
            circle.FillColor = UIColor.Clear.CGColor;

            circle.StrokeColor = color.CGColor;
            circle.LineWidth = 12;
            circle.StrokeStart = 0.0f;
            circle.StrokeEnd = strokeEnd;
            // add the created circle layer to the root layer of the view
            parent.Layer.AddSublayer (circle);

            return circle;

        }

        private CAShapeLayer animateDial (CAShapeLayer circle,UIView parent)
        {
            // Animate the Dial
            drawAnimation = CABasicAnimation.FromKeyPath ("strokeEnd");
            drawAnimation.Duration = 30.0;
            drawAnimation.RepeatCount = 1.0f;
            drawAnimation.From = NSNumber.FromFloat (0.0f);
            drawAnimation.To = NSNumber.FromFloat (1.0f);
            drawAnimation.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseIn);
            drawAnimation.RemovedOnCompletion = false;
            drawAnimation.Additive = true;
            drawAnimation.AnimationStopped += DrawAnimation_AnimationStopped;
            // add the defined animation to the cirecle created
            circle.AddAnimation (drawAnimation, "drawCircleAnimation");
            return circle;
        }

        void pauseLayer(CAShapeLayer layer)
        {
            layer.Speed = 0.0f;
            layer.TimeOffset = layer.ConvertTimeFromLayer (CAAnimation.CurrentMediaTime(), layer);

        }

        void resumeLayer(CAShapeLayer layer )
        {
            double pausedTime = layer.TimeOffset;
            layer.Speed = 1.0f;
            layer.TimeOffset = 0.0;
            layer.BeginTime = 0.0;
            double timesincePause = layer.ConvertTimeFromLayer (CAAnimation.CurrentMediaTime (),layer)-pausedTime;
            layer.BeginTime = timesincePause;
        }