Example #1
0
        private void AddShakeAnimation(UIView view, NSAction onAnimationStopped)
        {
            var curve = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

            var shakeAnimation = CAKeyFrameAnimation.GetFromKeyPath("transform.translation.x");

            shakeAnimation.RemovedOnCompletion = false;
            shakeAnimation.TimingFunction      = curve;
            shakeAnimation.Duration            = Duration;
            shakeAnimation.Values = new NSNumber[] {
                NSNumber.FromFloat(0),
                NSNumber.FromFloat(10),
                NSNumber.FromFloat(-8),
                NSNumber.FromFloat(8),
                NSNumber.FromFloat(-5),
                NSNumber.FromFloat(5),
                NSNumber.FromFloat(0)
            };
            shakeAnimation.KeyTimes = new NSNumber[] {
                NSNumber.FromFloat(0f),
                NSNumber.FromFloat(0.225f),
                NSNumber.FromFloat(0.425f),
                NSNumber.FromFloat(0.6f),
                NSNumber.FromFloat(0.75f),
                NSNumber.FromFloat(0.875f),
                NSNumber.FromFloat(1f),
            };

            if (onAnimationStopped != null)
            {
                shakeAnimation.AnimationStopped += (o, e) => onAnimationStopped();
            }

            view.Layer.AddAnimation(shakeAnimation, "shake");
        }
        public void BounceAnimation(nfloat positionX, nfloat positionY)
        {
            waveLayer.Path = WavePath(0, 0);
            var bounce = CAKeyFrameAnimation.GetFromKeyPath("path");

            bounce.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
            var values = new[] {
                WavePath(positionX, positionY),
                WavePath(-(positionX * 0.7f), -(positionY * 0.7f)),
                WavePath(positionX * 0.4f, positionY * 0.4f),
                WavePath(-(positionX * 0.3f), -(positionY * 0.3f)),
                WavePath(positionX * 0.15f, positionY * 0.15f),
                WavePath(0f, 0f)
            };

            bounce.SetValues(values);
            bounce.Duration            = BounceDuration;
            bounce.RemovedOnCompletion = true;
            bounce.FillMode            = CAFillMode.Forwards;
            bounce.AnimationStopped   += delegate
            {
                waveLayer.Path = WavePath(0f, 0f);
            };
            waveLayer.AddAnimation(bounce, "return");
        }
Example #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            animationPath   = new CGPath();
            backgroundImage = new UIImageView(View.Frame);
            View.AddSubview(backgroundImage);

            CreatePath();

            btnContents.TouchUpInside += (sender, e) => {
                if (ContentsButtonClicked != null)
                {
                    ContentsButtonClicked(sender, e);
                }
            };

            btnAnimate.TouchUpInside += (s, e) => {
                // create a keyframe animation
                var keyFrameAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.GetFromKeyPath("position");
                keyFrameAnimation.Path     = animationPath;
                keyFrameAnimation.Duration = 3;

                keyFrameAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

                imgToAnimate.Layer.AddAnimation(keyFrameAnimation, "MoveImage");
                imgToAnimate.Layer.Position = new PointF(700f, 900f);
            };
        }
        private CAKeyFrameAnimation PlusKeyFrame(bool closed)
        {
            UIBezierPath[] uiBezierPathArray1;
            if (closed)
            {
                uiBezierPathArray1 = new []
                {
                    PathPlus(CoreGraphicsExtensions.Pi * 0.0f),
                    PathPlus(CoreGraphicsExtensions.Pi * 0.125f),
                    PathPlus(CoreGraphicsExtensions.Pi * 0.25f)
                }
            }
            ;
            else
            {
                uiBezierPathArray1 = new[]
                {
                    PathPlus(CoreGraphicsExtensions.Pi * 0.25f),
                    PathPlus(CoreGraphicsExtensions.Pi * 0.125f),
                    PathPlus(CoreGraphicsExtensions.Pi * 0.0f)
                }
            };
            var uiBezierPathArray2 = uiBezierPathArray1;
            var fromKeyPath        = CAKeyFrameAnimation.GetFromKeyPath("path");

            // ISSUE: reference to a compiler-generated method
            fromKeyPath.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            var values = uiBezierPathArray2.Select(x => x.CGPath).ToArray();

            fromKeyPath.SetValues(value: values);
            fromKeyPath.Duration            = 0.5;
            fromKeyPath.RemovedOnCompletion = true;
            fromKeyPath.FillMode            = CAFillMode.Forwards;
            return(fromKeyPath);
        }
Example #5
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            //Creates basic moving animation
            var pt = layer.Position;

            layer.Position = new CGPoint(100, 300);
            var basicAnimation = CABasicAnimation.FromKeyPath("position");

            basicAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            basicAnimation.From           = NSValue.FromCGPoint(pt);
            basicAnimation.To             = NSValue.FromCGPoint(new CGPoint(100, 300));


            //Creates transformation animation
            layer.Transform = CATransform3D.MakeRotation((float)Math.PI * 2, 0, 0, 1);
            var animRotate = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform");

            animRotate.Values = new NSObject[] {
                NSNumber.FromFloat(0f),
                NSNumber.FromFloat((float)Math.PI / 2f),
                NSNumber.FromFloat((float)Math.PI),
                NSNumber.FromFloat((float)Math.PI * 2)
            };
            animRotate.ValueFunction = CAValueFunction.FromName(CAValueFunction.RotateX);

            //Adds the animations to a group, and adds the group to the layer
            var animationGroup = CAAnimationGroup.CreateAnimation();

            animationGroup.Duration   = 2;
            animationGroup.Animations = new CAAnimation[] { basicAnimation, animRotate };
            layer.AddAnimation(animationGroup, null);
        }
Example #6
0
            public override CAAnimation AnimationForSeries(TKChart chart, TKChartSeries series, TKChartSeriesRenderState state, CGRect rect)
            {
                double             duration   = 0;
                List <CAAnimation> animations = new List <CAAnimation>();

                for (int i = 0; i < (int)state.Points.Count; i++)
                {
                    string pointKeyPath = state.AnimationKeyPathForPointAtIndex((uint)i);

                    string keyPath        = string.Format("{0}.distanceFromCenter", pointKeyPath);
                    CAKeyFrameAnimation a = CAKeyFrameAnimation.GetFromKeyPath(keyPath);
                    a.Values   = new NSNumber[] { new NSNumber(50), new NSNumber(50), new NSNumber(0) };
                    a.KeyTimes = new NSNumber[] { new NSNumber(0), new NSNumber(i / (i + 1.0)), new NSNumber(1) };
                    a.Duration = 0.3 * (i + 1.1);
                    animations.Add(a);

                    keyPath    = string.Format("{0}.opacity", pointKeyPath);
                    a          = CAKeyFrameAnimation.GetFromKeyPath(keyPath);
                    a.Values   = new NSNumber[] { new NSNumber(0), new NSNumber(0), new NSNumber(1) };
                    a.KeyTimes = new NSNumber[] { new NSNumber(0), new NSNumber(i / (i + 1.0)), new NSNumber(1) };
                    a.Duration = 0.3 * (i + 1.1);
                    animations.Add(a);

                    duration = a.Duration;
                }
                CAAnimationGroup g = new CAAnimationGroup();

                g.Duration   = duration;
                g.Animations = animations.ToArray();
                return(g);
            }
Example #7
0
        void CreateKeyframeAnimation()
        {
            // animate the position
            PointF fromPt = _sublayer.Position;

            _sublayer.Position = new PointF(200, 300);
            CGPath path = new CGPath();

            path.AddLines(new PointF[] { fromPt, new PointF(250, 225), new PointF(100, 250), new PointF(200, 300) });
            CAKeyFrameAnimation animPosition = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position");

            animPosition.Path     = path;
            animPosition.Duration = 2;
            _sublayer.AddAnimation(animPosition, "position");

            // animate the layer transform
            _sublayer.Transform = CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1);
            CAKeyFrameAnimation animRotate = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform");

            animRotate.Values = new NSObject[] { NSNumber.FromCATransform3D(CATransform3D.MakeRotation(0, 0, 0, 1)),
                                                 NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI / 2f, 0, 0, 1)),
                                                 NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1)) };

            /* see bug comment below
             * animRotate.Values = new NSObject[] {
             *  NSNumber.FromFloat (0f),
             *  NSNumber.FromFloat ((float)Math.PI / 2f),
             *  NSNumber.FromFloat ((float)Math.PI) };
             */
            //BUG: MonoTouch does not have this class method bound as of MonoTouch Versino 3.1.3
            //animRotate.ValueFunction = CAValueFunction.FunctionWithName(CAValueFunction.RotateZ);

            animRotate.Duration = 2;
            _sublayer.AddAnimation(animRotate, "transform");
        }
Example #8
0
 protected CAKeyFrameAnimation CreateKeyFrame(string keyPath, string timingFuncName, params float[] values)
 {
     return(CAKeyFrameAnimation
            .FromKeyPath(keyPath)
            .SetTimingFunc((NSString)NSObject.FromObject(timingFuncName))        // CAMediaTimingFunction.Linear
            .SetValues(values));
 }
        // set up an animation, but prevent it from running automatically
        // the animation progress will be adjusted manually
        public void SetAnimatedColors(UIColor[] animatedColors, NSNumber[] keyTimes)
        {
            var cgColors = new List <NSObject>();

            foreach (var col in animatedColors)
            {
                cgColors.Add(NSObject.FromObject(col.CGColor));
            }

            var colorAnim = CAKeyFrameAnimation.FromKeyPath(SliderFillColorAnim);

            colorAnim.KeyTimes     = keyTimes;
            colorAnim.Values       = cgColors.ToArray();
            colorAnim.FillMode     = CAFillMode.Both;
            colorAnim.Duration     = 1.0;
            colorAnim.WeakDelegate = this;

            // As the interpolated color values from the presentationLayer are needed immediately
            // the animation must be allowed to start to initialize _colorAnimLayer's presentationLayer
            // hence the speed is set to min value - then set to zero in 'animationDidStart:' delegate method
            colorAnimLayer.Speed = 1.175494351e-38F;              // FLT_MIN
            //colorAnimLayer.Speed = 0.0000000000000000000000000000000000000117549435f;
            colorAnimLayer.TimeOffset = 0.0;

            colorAnimLayer.AddAnimation(colorAnim, SliderFillColorAnim);
        }
Example #10
0
		public void Position ()
		{
			var startPosition = solidView.Layer.Position;
			
			var a = new CAKeyFrameAnimation {
				KeyTimes = new [] {
					NSNumber.FromDouble (0),
					NSNumber.FromDouble (0.25),
					NSNumber.FromDouble (0.5),
					NSNumber.FromDouble (0.625),
					NSNumber.FromDouble (0.75),
					NSNumber.FromDouble (0.75+0.125/2),
					NSNumber.FromDouble (0.75+0.125),
					NSNumber.FromDouble (1),
				},
				Values = new NSObject[] {
					NSValue.FromPointF (startPosition),
					NSValue.FromPointF (new PointF (startPosition.X, startPosition.Y-100)),
					NSValue.FromPointF (startPosition),
					NSValue.FromPointF (new PointF (startPosition.X, startPosition.Y-25)),
					NSValue.FromPointF (startPosition),
					NSValue.FromPointF (new PointF (startPosition.X, startPosition.Y-12.5f)),
					NSValue.FromPointF (startPosition),
				},
				TimingFunction = CAMediaTimingFunction.FromName (
					CAMediaTimingFunction.EaseInEaseOut),
				Duration = 4,
				KeyPath = "position",
			};
			solidView.Layer.AddAnimation (a, "PositionAnimation");
		}
Example #11
0
        public static void Pop(this UIView view, double duration, int repeatCount, float force, double delay = 0)
        {
            CAKeyFrameAnimation animation = CAKeyFrameAnimation.FromKeyPath("transform.scale");

            animation.BeginTime      = CAAnimation.CurrentMediaTime() + delay;
            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            animation.KeyTimes       = new[]
            {
                NSNumber.FromFloat(0),
                NSNumber.FromFloat(0.2f),
                NSNumber.FromFloat(0.4f),
                NSNumber.FromFloat(0.6f),
                NSNumber.FromFloat(0.8f),
                NSNumber.FromFloat(1)
            };
            animation.Duration    = duration;
            animation.Additive    = true;
            animation.RepeatCount = repeatCount;
            animation.Values      = new NSObject[]
            {
                NSNumber.FromFloat(0),
                NSNumber.FromFloat(0.2f * force),
                NSNumber.FromFloat(-0.2f * force),
                NSNumber.FromFloat(0.2f * force),
                NSNumber.FromFloat(0)
            };
            if (view.Hidden)
            {
                view.Hidden = false;
            }
            view.Layer.AddAnimation(animation, "pop");
        }
        private void StartAnimatingTransaction()
        {
            CATransaction.Begin();


            float M_PI_2 = ((float)(Math.PI)) / 2.0f;

            CGAffineTransform tnull = CGAffineTransform.MakeIdentity();

            CGPath circlePath = new CGPath();

            circlePath.MoveToPoint(tnull, Frame.Width / 2.0f, Frame.Height - circleSize / 2.0f);
            circlePath.AddArc(tnull, Frame.Width / 2.0f, Frame.Height / 2.0f, radius - 15 / 2, M_PI_2, -M_PI_2 * 3, false);

            for (int i = 0; i < Layer.Sublayers.Length; i++)
            {
                CALayer circleLayer = Layer.Sublayers[i];

                CAKeyFrameAnimation circleAnimation = CAKeyFrameAnimation.GetFromKeyPath("position");
                circleAnimation.BeginTime       = CAAnimation.CurrentMediaTime() + 0.2f * i;
                circleAnimation.Duration        = 1.5;
                circleAnimation.TimingFunction  = CAMediaTimingFunction.FromControlPoints(0.15f, 0.60f, 0.85f, 0.4f);
                circleAnimation.CalculationMode = CAKeyFrameAnimation.AnimationPaced;
                circleAnimation.Path            = circlePath;
                circleAnimation.RepeatCount     = float.MaxValue;
                if (circleLayer == this.Layer.Sublayers[Layer.Sublayers.Length - 1])
                {
                    circleAnimation.WeakDelegate = this;
                }
                circleLayer.AddAnimation(circleAnimation, "circleAnimation");
            }
            //CGPathRelease(circlePath);

            CATransaction.Commit();
        }
Example #13
0
            public override CAAnimation AnimationForSeries(TKChart chart, TKChartSeries series, TKChartSeriesRenderState state, CGRect rect)
            {
                double             duration   = 0.5;
                List <CAAnimation> animations = new List <CAAnimation> ();

                for (int i = 0; i < (int)state.Points.Count; i++)
                {
                    string              keyPath = string.Format("seriesRenderStates.{0}.points.{1}.y", series.Index, i);
                    TKChartVisualPoint  point   = (TKChartVisualPoint)state.Points.ObjectAtIndex((uint)i);
                    double              oldY    = rect.Height;
                    double              half    = oldY + (point.Y - oldY) / 2.0;
                    CAKeyFrameAnimation a       = (CAKeyFrameAnimation)CAKeyFrameAnimation.GetFromKeyPath(keyPath);
                    a.KeyTimes       = new NSNumber[] { new NSNumber(0), new NSNumber(0), new NSNumber(1) };
                    a.Values         = new NSObject[] { new NSNumber(oldY), new NSNumber(half), new NSNumber(point.Y) };
                    a.Duration       = duration;
                    a.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
                    animations.Add(a);
                }

                CAAnimationGroup group = new CAAnimationGroup();

                group.Duration   = duration;
                group.Animations = animations.ToArray();

                return(group);
            }
        public void Position()
        {
            var startPosition = solidView.Layer.Position;

            var a = new CAKeyFrameAnimation {
                KeyTimes = new [] {
                    NSNumber.FromDouble(0),
                    NSNumber.FromDouble(0.25),
                    NSNumber.FromDouble(0.5),
                    NSNumber.FromDouble(0.625),
                    NSNumber.FromDouble(0.75),
                    NSNumber.FromDouble(0.75 + 0.125 / 2),
                    NSNumber.FromDouble(0.75 + 0.125),
                    NSNumber.FromDouble(1),
                },
                Values = new NSObject[] {
                    NSValue.FromPointF(startPosition),
                    NSValue.FromPointF(new PointF(startPosition.X, startPosition.Y - 100)),
                    NSValue.FromPointF(startPosition),
                    NSValue.FromPointF(new PointF(startPosition.X, startPosition.Y - 25)),
                    NSValue.FromPointF(startPosition),
                    NSValue.FromPointF(new PointF(startPosition.X, startPosition.Y - 12.5f)),
                    NSValue.FromPointF(startPosition),
                },
                TimingFunction = CAMediaTimingFunction.FromName(
                    CAMediaTimingFunction.EaseInEaseOut),
                Duration = 4,
                KeyPath  = "position",
            };

            solidView.Layer.AddAnimation(a, "PositionAnimation");
        }
Example #15
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            // get the initial value to start the animation from
            CGPoint fromPt = layer.Position;

            // set the position to coincide with the final animation value
            // to prevent it from snapping back to the starting position
            // after the animation completes
            layer.Position = new CGPoint(200, 300);

            // create a path for the animation to follow
            CGPath path = new CGPath();

            path.AddLines(new CGPoint[] { fromPt, new CGPoint(50, 300), new CGPoint(200, 50), new CGPoint(200, 300) });

            // create a keyframe animation for the position using the path
            CAKeyFrameAnimation animPosition = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position");

            animPosition.Path     = path;
            animPosition.Duration = 2;

            // add the animation to the layer
            // the "position" key is used to overwrite the implicit animation created
            // when the layer positino is set above
            layer.AddAnimation(animPosition, "position");
        }
        public void Shake(double duration = 0.5)
        {
            var animation = CAKeyFrameAnimation.GetFromKeyPath("transform.translation.x");

            animation.Delegate = this;
            animation.Duration = duration;
            animation.Values   = new NSObject[]
            {
                NSNumber.FromFloat(0),
                NSNumber.FromFloat(10),
                NSNumber.FromFloat(-8),
                NSNumber.FromFloat(8),
                NSNumber.FromFloat(-5),
                NSNumber.FromFloat(5),
                NSNumber.FromFloat(0)
            };
            animation.KeyTimes = new NSNumber[]
            {
                new NSNumber(0),
                new NSNumber(0.225),
                new NSNumber(0.425),
                new NSNumber(0.6),
                new NSNumber(0.75),
                new NSNumber(0.875),
                new NSNumber(1)
            };
            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

            foreach (var view in this.views)
            {
                view.Layer.AddAnimation(animation, ANIMATION_KEY);
            }
        }
Example #17
0
        void CreateAnimationGroup()
        {
            PointF fromPt = _sublayer.Position;

            _sublayer.Position = new PointF(200, 300);
            CGPath path = new CGPath();

            path.AddLines(new PointF[] { fromPt, new PointF(250, 225), new PointF(100, 250), new PointF(200, 300) });
            CAKeyFrameAnimation animPosition = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position");

            animPosition.Path = path;

            _sublayer.Transform = CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1);
            CAKeyFrameAnimation animRotate = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform");

            animRotate.Values = new NSObject[] { NSNumber.FromCATransform3D(CATransform3D.MakeRotation(0, 0, 0, 1)),
                                                 NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI / 2f, 0, 0, 1)),
                                                 NSNumber.FromCATransform3D(CATransform3D.MakeRotation((float)Math.PI, 0, 0, 1)) };

            CAAnimationGroup spinningMonkeyGroup = CAAnimationGroup.CreateAnimation();

            spinningMonkeyGroup.Duration   = 2;
            spinningMonkeyGroup.Animations = new CAAnimation[] { animPosition, animRotate };
            _sublayer.AddAnimation(spinningMonkeyGroup, null);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //---- add our background image view that we'll show our path on
            this._backgroundImage = new UIImageView(this.View.Frame);
            this.View.AddSubview(this._backgroundImage);

            //---- create our path
            this.CreatePath();

            this.btnAnimate.TouchUpInside += (s, e) => {
                //---- create a keyframe animation
                CAKeyFrameAnimation keyFrameAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position");
                keyFrameAnimation.Path     = this._animationPath;
                keyFrameAnimation.Duration = 3;

                keyFrameAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

                this.imgToAnimate.Layer.AddAnimation(keyFrameAnimation, "MoveImage");
                this.imgToAnimate.Layer.Position = new PointF(700, 900);

                // later, if we want to stop/remove the animation, we can call RemoveAnimation and pass the name:
                //this.imgToAnimate.Layer.RemoveAnimation("MoveImage");
            };
        }
Example #19
0
 public override void RemoveAllAnimations()
 {
     base.RemoveAllAnimations();
     ForegroundOpacityAnim  = null;
     ForegroundPositionAnim = null;
     ForegroundScaleAnim    = null;
     AnimationCleared       = true;
 }
Example #20
0
        private static CAKeyFrameAnimation SetupFadeAnimation(nfloat fadeTime)
        {
            var fade = CAKeyFrameAnimation.FromKeyPath("opacity");

            fade.Values   = new[] { NSObject.FromObject(1.0), NSObject.FromObject(1.0), NSObject.FromObject(0.5), NSObject.FromObject(0.5), NSObject.FromObject(0.0) };
            fade.Duration = fadeTime;
            return(fade);
        }
Example #21
0
        private CAKeyFrameAnimation CreateTrackingAnimation(CGPath path)
        {
            var animation = CAKeyFrameAnimation.FromKeyPath("position");

            animation.Path     = path;
            animation.Duration = sessionDurationInSeconds;

            return(animation);
        }
Example #22
0
        async Task animateView(UIView view)
        {
            var size   = view.Frame.Size;
            var grow   = new SizeF(size.Width * 1.7f, size.Height * 1.7f);
            var shrink = new SizeF(size.Width * .4f, size.Height * .4f);
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool> ();
            //Set the animation path
            var pathAnimation = CAKeyFrameAnimation.GetFromKeyPath("position");

            pathAnimation.CalculationMode     = CAAnimation.AnimationPaced;
            pathAnimation.FillMode            = CAFillMode.Forwards;
            pathAnimation.RemovedOnCompletion = false;
            pathAnimation.Duration            = .5;

            UIBezierPath path = new UIBezierPath();

            path.MoveTo(view.Center);
            path.AddQuadCurveToPoint(new PointF(290, 34), new PointF(view.Center.X, View.Center.Y));
            pathAnimation.Path = path.CGPath;

            //Set size change
            var growAnimation = CABasicAnimation.FromKeyPath("bounds.size");

            growAnimation.To                  = NSValue.FromSizeF(grow);
            growAnimation.FillMode            = CAFillMode.Forwards;
            growAnimation.Duration            = .1;
            growAnimation.RemovedOnCompletion = false;



            var shrinkAnimation = CABasicAnimation.FromKeyPath("bounds.size");

            shrinkAnimation.To                  = NSValue.FromSizeF(shrink);
            shrinkAnimation.FillMode            = CAFillMode.Forwards;
            shrinkAnimation.Duration            = .4;
            shrinkAnimation.RemovedOnCompletion = false;
            shrinkAnimation.BeginTime           = .1;


            CAAnimationGroup animations = new CAAnimationGroup();

            animations.FillMode            = CAFillMode.Forwards;
            animations.RemovedOnCompletion = false;
            animations.Animations          = new CAAnimation[] {
                pathAnimation,
                growAnimation,
                shrinkAnimation,
            };
            animations.Duration          = .5;
            animations.AnimationStopped += (sender, e) => {
                tcs.TrySetResult(true);
            };
            view.Layer.AddAnimation(animations, "movetocart");
            NSTimer.CreateScheduledTimer(.5, () => view.RemoveFromSuperview());
            await tcs.Task;
        }
            public override CAAnimation AnimationForSeries(TKChart chart, TKChartSeries series, TKChartSeriesRenderState state, CGRect rect)
            {
                double             duration   = 0;
                List <CAAnimation> animations = new List <CAAnimation> ();

                for (int i = 0; i < (int)state.Points.Count; i++)
                {
                    TKChartVisualPoint point = (TKChartVisualPoint)state.Points.ObjectAtIndex((uint)i);

                    if (Grow)
                    {
                        string keyPath = string.Format("seriesRenderStates.{0}.points.{1}.x", series.Index, i);

                        CABasicAnimation animation = (CABasicAnimation)CABasicAnimation.FromKeyPath(keyPath);
                        animation.Duration       = 0.1 * (i + 0.2);
                        animation.From           = new NSNumber(0);
                        animation.To             = new NSNumber(point.X);
                        animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
                        animations.Add(animation);

                        duration = animation.Duration;
                    }
                    else
                    {
                        string keyPath = string.Format("seriesRenderStates.{0}.points.{1}.y", series.Index, i);
                        nfloat oldY    = rect.Height;

                        if (i > 0)
                        {
                            CAKeyFrameAnimation animation = (CAKeyFrameAnimation)CAKeyFrameAnimation.GetFromKeyPath(keyPath);
                            animation.Duration       = 0.1 * (i + 1);
                            animation.Values         = new NSNumber[] { new NSNumber(oldY), new NSNumber(oldY), new NSNumber(point.Y) };
                            animation.KeyTimes       = new NSNumber[] { new NSNumber(0), new NSNumber(i / (i + 1.0)), new NSNumber(1) };
                            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
                            animations.Add(animation);

                            duration = animation.Duration;
                        }
                        else
                        {
                            CABasicAnimation animation = (CABasicAnimation)CABasicAnimation.FromKeyPath(keyPath);
                            animation.From     = new NSNumber(oldY);
                            animation.To       = new NSNumber(point.Y);
                            animation.Duration = 0.1f;
                            animations.Add(animation);
                        }
                    }
                }

                CAAnimationGroup group = new CAAnimationGroup();

                group.Duration   = duration;
                group.Animations = animations.ToArray();

                return(group);
            }
Example #24
0
        public void StartAnimation()
        {
            var checkmarkStrokeAnimation = CAKeyFrameAnimation.FromKeyPath("strokeEnd");

            checkmarkStrokeAnimation.Values   = new NSObject[] { new NSNumber(0), new NSNumber(1) };
            checkmarkStrokeAnimation.KeyTimes = new[] { new NSNumber(0), new NSNumber(1) };
            checkmarkStrokeAnimation.Duration = .35f;

            _checkmarkShapeLayer?.AddAnimation(checkmarkStrokeAnimation, "checkmarkStrokeAnimation");
        }
Example #25
0
        protected override void Prepare(UIView view)
        {
            var animationAlpha = CAKeyFrameAnimation
                                 .FromKeyPath(Opacity)
                                 .SetValues(0f, 1f);
            var animationRotate = CAKeyFrameAnimation
                                  .FromKeyPath(TransformRotation)
                                  .SetValues(DegreesToRadians(-200), 0f);

            PlayTogether(animationAlpha, animationRotate);
        }
        void HandleDownloadEvent(LibraryBookView bookView)
        {
            try
            {
                if (!downloadAnimation)
                {
                    downloadAnimation = true;

                    // Remove from collectionView
                    bookView.RemoveFromSuperview();

                    // Add to the current view at exact position
                    NSIndexPath indexPath = dataSource.GetIndexPath(bookView.LibraryBook.ID);
                    UICollectionViewLayoutAttributes attributes = collectionView.GetLayoutAttributesForItem(indexPath);
                    bookView.Frame = new CGRect(attributes.Frame.X + collectionView.Frame.X, attributes.Frame.Y - collectionView.ContentOffset.Y, attributes.Frame.Width, attributes.Frame.Height);
                    this.View.AddSubview(bookView);

                    // Fly Animation
                    CGPoint startPoint = new CGPoint(bookView.Frame.X + bookView.Frame.Width / 2, bookView.Frame.Y + bookView.Frame.Height / 2);
                    CGPoint endPoint   = new CGPoint(Settings.MyBooksTabLocation.X + 76f / 2f, this.View.Frame.Bottom + 55f / 2f);

                    UIView.Animate(0.75d, delegate
                    {
                        bookView.Transform = CGAffineTransform.MakeScale(0.1f, 0.1f);
                        bookView.Center    = endPoint;
                        bookView.Alpha     = 0.5f;

                        // Prepare my own keypath animation for the layer position
                        CGPath animationPath = CreatePath(startPoint, endPoint);
                        CAKeyFrameAnimation keyFrameAnimation = CAKeyFrameAnimation.GetFromKeyPath("position");
                        keyFrameAnimation.Path = animationPath;

                        // Copy properties from UIView's animation
                        CAAnimation autoAnimation        = bookView.Layer.AnimationForKey("position");
                        keyFrameAnimation.Duration       = autoAnimation.Duration;
                        keyFrameAnimation.FillMode       = autoAnimation.FillMode;
                        keyFrameAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

                        // Replace UIView's animation with my animation
                        bookView.Layer.AddAnimation(keyFrameAnimation, keyFrameAnimation.KeyPath);
                    }, delegate
                    {
                        this.InvokeOnMainThread(delegate
                        {
                            UpdateCollectionView(bookView);
                        });
                    });
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLineDebugging("LibraryViewController - HandleDownloadEvent: {0}", ex.ToString());
            }
        }
Example #27
0
 private CAKeyFrameAnimation ScaleAnimWithValues(NSNumber[] values,
                                         NSNumber[] times)
 {
     CAKeyFrameAnimation anim = CAKeyFrameAnimation.FromKeyPath(kInkLayerScale);
     anim.FillMode = CAFillMode.Forwards;
     anim.KeyTimes = times;
     anim.RemovedOnCompletion = false;
     anim.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
     anim.Values = values;
      return anim;
 }
        public static void Shake(this UIView view)
        {
            var animation = new CAKeyFrameAnimation {
                KeyPath = "transform.translation.x"
            };

            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
            animation.Duration       = 0.6f;
            animation.Values         = new NSNumber[] { -20.0, 20.0, -20.0, 20.0, -10.0, 10.0, -5.0, 5.0, 0.0 };
            view.Layer.AddAnimation(animation, "shake");
        }
Example #29
0
        public static CAKeyFrameAnimation SetValues(this CAKeyFrameAnimation frameAnimation, params float[] values)
        {
            var list = new List <NSNumber>();

            foreach (var value in values)
            {
                list.Add(NSNumber.FromFloat(value));
            }
            frameAnimation.Values = list.ToArray();
            return(frameAnimation);
        }
Example #30
0
        private CAKeyFrameAnimation CreateTrackingAnimation()
        {
            var start       = getStartingPoint();
            var endingPoint = getEndingPoint();

            var animation = CAKeyFrameAnimation.FromKeyPath("position");

            animation.Path     = GenerateRandomPath(start);
            animation.Duration = 2;

            return(animation);
        }
Example #31
0
 protected CAKeyFrameAnimation PositionAnimWithPath(CGPath path,
                              nfloat duration,
                                                  CAMediaTimingFunction timingFunction)
 {
     CAKeyFrameAnimation anim = CAKeyFrameAnimation.FromKeyPath(kInkLayerPosition);
     anim.Duration = duration;
     anim.FillMode = CAFillMode.Forwards;
     anim.Path = path;
     anim.RemovedOnCompletion = false;
     anim.TimingFunction = timingFunction;
     return anim;
 }
		private CAAnimation frameAnimation (CGRect aniFrame)
		{
			CAKeyFrameAnimation frameAni = new CAKeyFrameAnimation ();
			
			frameAni.KeyPath = "frame";
			CGRect start = aniFrame;
			CGRect end = aniFrame.Inset (-start.Width * .5f, -start.Height * 0.5f);
			frameAni.Values = new NSObject[] { 
				NSValue.FromCGRect (start),
				NSValue.FromCGRect (end)
			};
			return frameAni;
		}
Example #33
0
		public void CornerRadius ()
		{
			var a = new CAKeyFrameAnimation {
				KeyTimes = new [] {
					NSNumber.FromDouble (0),
					NSNumber.FromDouble (0.1),
					NSNumber.FromDouble (0.5),
					NSNumber.FromDouble (0.9),
					NSNumber.FromDouble (1),
				},
				Values = new NSObject[] {
					NSNumber.FromFloat (5),
					NSNumber.FromFloat (50),
					NSNumber.FromFloat (25),
					NSNumber.FromFloat (50),
					NSNumber.FromFloat (5),
				},
				Duration = 2,
				KeyPath = "cornerRadius",
			};
			solidView.Layer.AddAnimation (a, "CornerRadiusAnimation");
		}
        private static UIImageView CreateAnimatedImageView(CGImageSource imageSource, UIImageView imageView = null)
        {
            var frameCount = imageSource.ImageCount;

            var frameImages = new List<NSObject>((int)frameCount);
            var frameCGImages = new List<CGImage>((int)frameCount);
            var frameDurations = new List<double>((int)frameCount);

            var totalFrameDuration = 0.0;

            for (int i = 0; i < frameCount; i++)
            {
                var frameImage = imageSource.CreateImage(i, null);

                frameCGImages.Add(frameImage);
                frameImages.Add(NSObject.FromObject(frameImage));

                var properties = imageSource.GetProperties(i, null);
                var duration = properties.Dictionary["{GIF}"];
                var delayTime = duration.ValueForKey(new NSString("DelayTime"));
                duration.Dispose ();
                var realDuration = double.Parse(delayTime.ToString());
                frameDurations.Add(realDuration);
                totalFrameDuration += realDuration;
                frameImage.Dispose ();
            }

            var framePercentageDurations = new List<NSNumber>((int)frameCount);
            var framePercentageDurationsDouble = new List<double>((int)frameCount);
            NSNumber currentDurationPercentage = 0.0f;
            double currentDurationDouble = 0.0f;
            for (int i = 0; i < frameCount; i++)
            {
                if (i != 0)
                {
                    var previousDuration = frameDurations[i - 1];
                    var previousDurationPercentage = framePercentageDurationsDouble[i - 1];

                    var number = previousDurationPercentage + (previousDuration/totalFrameDuration);
                    currentDurationDouble = number;
                    currentDurationPercentage = new NSNumber(number);
                }
                framePercentageDurationsDouble.Add(currentDurationDouble);
                framePercentageDurations.Add(currentDurationPercentage);
            }

            var imageSourceProperties = imageSource.GetProperties(null);
            var imageSourceGIFProperties = imageSourceProperties.Dictionary["{GIF}"];
            var loopCount = imageSourceGIFProperties.ValueForKey(new NSString("LoopCount"));
            var imageSourceLoopCount = float.Parse(loopCount.ToString());
            var frameAnimation = new CAKeyFrameAnimation();
            frameAnimation.KeyPath = "contents";
            if (imageSourceLoopCount <= 0.0f)
            {
                frameAnimation.RepeatCount = float.MaxValue;
            }
            else
            {
                frameAnimation.RepeatCount = imageSourceLoopCount;
            }

            imageSourceGIFProperties.Dispose ();


            frameAnimation.CalculationMode = CAAnimation.AnimationDescrete;
            frameAnimation.Values = frameImages.ToArray();
            frameAnimation.Duration = totalFrameDuration;
            frameAnimation.KeyTimes = framePercentageDurations.ToArray();
            frameAnimation.RemovedOnCompletion = false;
            var firstFrame = frameCGImages[0];
            if(imageView == null)
                imageView = new UIImageView(new CGRect(0.0f, 0.0f, firstFrame.Width, firstFrame.Height));
            else
                imageView.Layer.RemoveAllAnimations();

            imageView.Layer.AddAnimation(frameAnimation, "contents");

            frameAnimation.Dispose ();
            return imageView;
        }