Example #1
0
        public void Animate(long xAxisDuration, long yAxisDuration, EasingFunction easingX, EasingFunction easingY)
        {
            Stop();

            startTimeX = System.Diagnostics.Stopwatch.GetTimestamp();
            startTimeY = startTimeX;
            durationX  = xAxisDuration;
            durationY  = yAxisDuration;
            endTimeX   = startTimeX + xAxisDuration;
            endTimeY   = startTimeY + yAxisDuration;
            endTime    = endTimeX > endTimeY ? endTimeX : endTimeY;
            enabledX   = xAxisDuration > 0.0;
            enabledY   = yAxisDuration > 0.0;


            _easingX = easingX;
            _easingY = easingY;

            // Take care of the first frame if rendering is already scheduled...
            UpdateAnimationPhases(startTimeX);


            if (enabledX || enabledY)
            {
                displayLink = NSUIDisplayLink.Create(AnimationLoop);
                displayLink.AddToRunLoop(Foundation.NSRunLoop.Main, Foundation.NSRunLoopMode.Common);
            }
        }
Example #2
0
        public void Stop()
        {
            if (displayLink != null)
            {
                displayLink.RemoveFromRunLoop(Foundation.NSRunLoop.Main, Foundation.NSRunLoopMode.Common);
                displayLink = null;

                enabledX = false;
                enabledY = false;

                // If we stopped an animation in the middle, we do not want to leave it like this
                if (PhaseX != 1.0 || PhaseY != 1.0)
                {
                    PhaseX = 1.0f;
                    PhaseX = 1.0f;

                    Delegate.AnimatorUpdated(this);
                    UpdateBlock?.Invoke();
                }

                Delegate.AnimatorStopped(this);
                StopBlock?.Invoke();
            }
        }