public override void ViewDidLoad()
        {
            base.ViewDidLoad();

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

            // create our path
            CreatePath();

            btnAnimate.TouchUpInside += (s, e) => {
                // create a keyframe animation
                CAKeyFrameAnimation 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(700, 900);

                // later, if we want to stop/remove the animation, we can call RemoveAnimation and pass the name:
                //imgToAnimate.Layer.RemoveAnimation("MoveImage");
            };
        }
Example #2
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 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 #4
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);
            }
Example #5
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);
            };
        }
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);
            }
        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");
        }
        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);
        }
        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();
        }
            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 #11
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;
        }
        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());
            }
        }
        public void BounceTimeLabel()
        {
            // Create key frame animations
            CAKeyFrameAnimation bounce = CAKeyFrameAnimation.GetFromKeyPath("transform");
            CAKeyFrameAnimation fade   = CAKeyFrameAnimation.GetFromKeyPath("opacity");

            // Set the event handler for when the animations stop
            bounce.AnimationStopped += AnimationStopped;
            fade.AnimationStopped   += AnimationStopped;

            // Create the values the bounce animation will pass through
            CATransform3D forward  = CATransform3D.MakeScale(1.3f, 1.3f, 1.0f);
            CATransform3D back     = CATransform3D.MakeScale(0.7f, 0.7f, 1.0f);
            CATransform3D forward2 = CATransform3D.MakeScale(1.2f, 1.2f, 1.0f);
            CATransform3D back2    = CATransform3D.MakeScale(0.9f, 0.9f, 1.0f);

            // Create the values the opacity animation will use to transition between
            NSNumber opacity0 = NSNumber.FromFloat(0.0f);
            NSNumber opacity1 = NSNumber.FromFloat(1.0f);

            bounce.Values = new NSObject[] {
                // Start from the default values set in the XIB
                NSValue.FromCATransform3D(CATransform3D.Identity),
                NSValue.FromCATransform3D(forward),
                NSValue.FromCATransform3D(back),
                NSValue.FromCATransform3D(forward2),
                NSValue.FromCATransform3D(back2),
                // Return to the default values set in the XIB
                NSValue.FromCATransform3D(CATransform3D.Identity)
            };

            fade.Values = new NSObject[] {
                // Get the starting value form the modal layer
                NSNumber.FromFloat(lblTime.Layer.Opacity),
                opacity1,
                opacity0,
                opacity1,
                opacity0,
                // Get the ending value from the modal layer
                NSNumber.FromFloat(lblTime.Layer.Opacity)
            };

            // Set the animation duration
            bounce.Duration = 5.0f;
            fade.Duration   = 5.0f;

            // Animate the CALayer of the time label (lblTime)
            lblTime.Layer.AddAnimation(bounce, "bounceAnimation");
            lblTime.Layer.AddAnimation(fade, "fadeAnimation");
        }
Example #14
0
        public void BounceTimeLabel()
        {
            // Create a key frame animation
            CAKeyFrameAnimation bounce = CAKeyFrameAnimation.GetFromKeyPath("transform");
            CAKeyFrameAnimation fade   = CAKeyFrameAnimation.GetFromKeyPath("opacity");

            bounce.AnimationStopped += AnimationStopped;
            fade.AnimationStopped   += AnimationStopped;

            // Create the values it will pass through
            CATransform3D forward  = CATransform3D.MakeScale(1.3f, 1.3f, 1.0f);
            CATransform3D back     = CATransform3D.MakeScale(0.7f, 0.7f, 1.0f);
            CATransform3D forward2 = CATransform3D.MakeScale(1.2f, 1.2f, 1.0f);
            CATransform3D back2    = CATransform3D.MakeScale(0.9f, 0.9f, 1.0f);

            NSNumber opacity0 = NSNumber.FromFloat(0.0f);
            NSNumber opacity1 = NSNumber.FromFloat(1.0f);

            bounce.Values = new NSObject[] {
                NSValue.FromCATransform3D(CATransform3D.Identity),
                NSValue.FromCATransform3D(forward),
                NSValue.FromCATransform3D(back),
                NSValue.FromCATransform3D(forward2),
                NSValue.FromCATransform3D(back2),
                NSValue.FromCATransform3D(CATransform3D.Identity)
            };

            fade.Values = new NSObject[] {
                NSNumber.FromFloat(lblTime.Layer.Opacity),
                opacity1,
                opacity0,
                opacity1,
                opacity0,
                NSNumber.FromFloat(lblTime.Layer.Opacity)
            };

            // Set the duration
            bounce.Duration = 5.0f;
            fade.Duration   = 5.0f;

            // Animate the layer
            lblTime.Layer.AddAnimation(bounce, "bounceAnimation");
            lblTime.Layer.AddAnimation(fade, "fadeAnimation");
        }
Example #15
0
        public void FadeRepeat(object sender, CAAnimationStateEventArgs e)
        {
            //btnShowTime.Layer.RemoveAnimation("fadeInOUt");
            CAKeyFrameAnimation fade = CAKeyFrameAnimation.GetFromKeyPath("opacity");

            NSNumber opacity0 = NSNumber.FromFloat(0.0f);
            NSNumber opacity1 = NSNumber.FromFloat(1.0f);

            fade.Values = new NSObject[] {
                opacity1,
                opacity0,
                opacity1,
            };

            fade.Duration       = 1.0f;
            fade.RepeatDuration = 1000.0;

            btnShowTime.Layer.AddAnimation(fade, "fadeInOut");
        }
        private CAKeyFrameAnimation PlusKeyFrame(bool closed)
        {
            var paths = closed ? new[] {
                PathPlus(CoreGraphicsExtensions.PI * 0f),
                PathPlus(CoreGraphicsExtensions.PI * 0.125f),
                PathPlus(CoreGraphicsExtensions.PI * 0.25f),
            } : new[] {
                PathPlus(CoreGraphicsExtensions.PI * 0.25f),
                PathPlus(CoreGraphicsExtensions.PI * 0.125f),
                PathPlus(CoreGraphicsExtensions.PI * 0f),
            };
            var anim = CAKeyFrameAnimation.GetFromKeyPath("path");

            anim.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            anim.SetValues(paths.Select(x => x.CGPath).ToArray());
            anim.Duration            = 0.5f;
            anim.RemovedOnCompletion = true;
            anim.FillMode            = CAFillMode.Forwards;
            return(anim);
        }
Example #17
0
        public static UIView Pulse(this UIView view, float max)
        {
            var transformAnimation = CAKeyFrameAnimation.GetFromKeyPath("transform");

            transformAnimation.CalculationMode = CAAnimation.AnimationPaced;
            transformAnimation.FillMode        = CAFillMode.Forwards;
            transformAnimation.TimingFunction  = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            //			pathAnimation.RemovedOnCompletion = false;
            transformAnimation.Duration = .2;

            var transform = CATransform3D.MakeScale(max, max, 1);

            transformAnimation.Values = new [] {
                NSValue.FromCATransform3D(CATransform3D.Identity),
                NSValue.FromCATransform3D(transform),
                NSValue.FromCATransform3D(CATransform3D.Identity),
            };
            view.Layer.AddAnimation(transformAnimation, "pulse");
            return(view);
        }
        public void UpdateItemsCount(int count)
        {
            ItemsCount = count;
            var pathAnimation = CAKeyFrameAnimation.GetFromKeyPath("transform");

            pathAnimation.CalculationMode = CAAnimation.AnimationPaced;
            pathAnimation.FillMode        = CAFillMode.Forwards;
            pathAnimation.TimingFunction  = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
//			pathAnimation.RemovedOnCompletion = false;
            pathAnimation.Duration = .2;

            var transform = CATransform3D.MakeScale(2f, 2f, 1);

            pathAnimation.Values = new [] {
                NSValue.FromCATransform3D(CATransform3D.Identity),
                NSValue.FromCATransform3D(transform),
                NSValue.FromCATransform3D(CATransform3D.Identity),
            };
            badge.Layer.AddAnimation(pathAnimation, "pulse");
        }
Example #19
0
        private void SetupAnimationGroup()
        {
            if (animationGroup != null)
            {
                return;
            }

            var defaultCurve = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Default);

            animationGroup = new CAAnimationGroup();
            animationGroup.RemovedOnCompletion = true;
            animationGroup.Duration            = this.Duration + this.PulseInterval;
            animationGroup.RepeatCount         = this.repeatCount;
            animationGroup.TimingFunction      = defaultCurve;

            var scaleAnimation = CABasicAnimation.FromKeyPath("transform.scale.xy");

            scaleAnimation.RemovedOnCompletion = false;
            scaleAnimation.Duration            = this.Duration;
            scaleAnimation.From = NSObject.FromObject(fromValueForRadius);
            scaleAnimation.To   = NSObject.FromObject(1.0f);

            var opacityAnimation = CAKeyFrameAnimation.GetFromKeyPath("opacity");

            opacityAnimation.RemovedOnCompletion = false;
            opacityAnimation.Duration            = this.Duration;
            opacityAnimation.Values = new NSNumber[] {
                NSNumber.FromFloat(fromValueForAlpha),
                NSNumber.FromFloat(0.45f),
                NSNumber.FromFloat(0f),
            };
            opacityAnimation.KeyTimes = new NSNumber[] {
                NSNumber.FromFloat(0f),
                NSNumber.FromFloat(keyTimeForHalfOpacity),
                NSNumber.FromFloat(1f),
            };

            animationGroup.Animations = new CAAnimation[] { scaleAnimation, opacityAnimation };
        }
        public void FadeRepeat(object sender, CAAnimationStateEventArgs e)
        {
            //btnShowTime.Layer.RemoveAnimation("fadeInOUt");
            // Create a key frame animation
            CAKeyFrameAnimation fade = CAKeyFrameAnimation.GetFromKeyPath("opacity");

            // Set the opacities between which the show time button will cycle
            NSNumber opacity0 = NSNumber.FromFloat(0.0f);
            NSNumber opacity1 = NSNumber.FromFloat(1.0f);

            fade.Values = new NSObject[] {
                opacity1,
                opacity0,
                opacity1,
            };

            // Set the flashing speed
            fade.Duration = 1.0f;
            // Set hoew long the flashing will repeat for
            fade.RepeatDuration = 1000.0;

            // Add the animation to the show time button (btnShowTime) CALayer
            btnShowTime.Layer.AddAnimation(fade, "fadeInOut");
        }
        public void FlashImage(UIImageView iv)
        {
            // Create a key frame animation
            CAKeyFrameAnimation flash = CAKeyFrameAnimation.GetFromKeyPath("opacity");

            // Set the opacities between which the image view (iv) will cycle
            NSNumber opacity0 = NSNumber.FromFloat(0.1f);
            NSNumber opacity1 = NSNumber.FromFloat(1.0f);

            flash.Values = new NSObject[] {
                opacity1,
                opacity0,
                opacity1,
            };

            // Set the flashing speed
            flash.Duration = 2.0f;
            // Set hoew long the flashing will repeat for
            flash.RepeatDuration = 1000.0;


            // Add the animation to the imageView CALayer
            iv.Layer.AddAnimation(flash, "fadeInOut");
        }
Example #22
0
        private void PlaceFeature(string message, CGPoint p, float offset)
        {
            // Create and configure a node with a text geometry, and add it to the scene
            var text = SCNText.Create(message, 5);

            text.Font      = Font;
            text.Flatness  = 0.4f;
            text.Materials = Materials;

            var textNode = SCNNode.Create();

            textNode.Geometry = text;
            textNode.Position = new SCNVector3(p.X, p.Y + Altitude, 0);
            textNode.Scale    = new SCNVector3(0.02f, 0.02f, 0.02f);

            ContentNode.AddChildNode(textNode);

            // Animation the node's position and opacity
            var positionAnimation = CABasicAnimation.FromKeyPath("position.z");

            positionAnimation.From        = NSNumber.FromInt16(-10);
            positionAnimation.To          = NSNumber.FromInt16(10);
            positionAnimation.Duration    = 5.0f;
            positionAnimation.TimeOffset  = -offset * positionAnimation.Duration;
            positionAnimation.RepeatCount = float.MaxValue;
            textNode.AddAnimation(positionAnimation, new NSString("positionAnimation"));

            var opacityAnimation = CAKeyFrameAnimation.GetFromKeyPath("opacity");

            opacityAnimation.KeyTimes    = new NSNumber[] { 0.0f, 0.2f, 0.9f, 1.0f };
            opacityAnimation.Values      = new NSNumber[] { 0.0f, 1.0f, 1.0f, 0.0f };
            opacityAnimation.Duration    = positionAnimation.Duration;
            opacityAnimation.TimeOffset  = positionAnimation.TimeOffset;
            opacityAnimation.RepeatCount = float.MaxValue;
            textNode.AddAnimation(opacityAnimation, new NSString("opacityAnimation"));
        }
Example #23
0
        // Takes a string an creates a node hierarchy where each letter is an independent geometry that is animated
        private SCNNode SplittedStylizedText(string message)
        {
            var textNode      = SCNNode.Create();
            var frontMaterial = TextFrontMaterial();
            var border        = TextSideAndChamferMaterial();

            // Current x position of the next letter to add
            var positionX = 0.0f;

            // For each letter
            for (var i = 0; i < message.Length; i++)
            {
                var letterNode   = SCNNode.Create();
                var letterString = message.Substring(i, 1);
                var text         = SCNText.Create(letterString, 50.0f);
                text.Font = NSFont.FromFontName("Avenir Next Heavy", 288);

                text.ChamferRadius  = 3.0f;
                text.ChamferProfile = TextChamferProfile();

                // use a different material for the "heart" character
                var finalFrontMaterial = frontMaterial;
                if (i == 1)
                {
                    finalFrontMaterial = (SCNMaterial)finalFrontMaterial.Copy();
                    finalFrontMaterial.Diffuse.Contents    = NSColor.Red;
                    finalFrontMaterial.Reflective.Contents = NSColor.Black;
                    letterNode.Scale = new SCNVector3(1.1f, 1.1f, 1.0f);
                }

                text.Materials = new SCNMaterial[] { finalFrontMaterial, finalFrontMaterial, border, border, border };

                letterNode.Geometry = text;
                textNode.AddChildNode(letterNode);

                // measure the letter we just added to update the position
                SCNVector3 min, max;
                max = new SCNVector3(0, 0, 0);
                min = new SCNVector3(0, 0, 0);
                if (letterNode.GetBoundingBox(ref min, ref max))
                {
                    letterNode.Position = new SCNVector3(positionX - min.X + (max.X + min.X) * 0.5f, -min.Y, 0);
                    positionX          += (float)max.X;
                }
                else
                {
                    // if we have no bounding box, it is probably because of the "space" character. In that case, move to the right a little bit.
                    positionX += 50.0f;
                }

                // Place the pivot at the center of the letter so that the rotation animation looks good
                letterNode.Pivot = SCNMatrix4.CreateTranslation((max.X + min.X) * 0.5f, 0, 0);

                // Animate the letter
                var animation = CAKeyFrameAnimation.GetFromKeyPath("rotation");
                animation.Duration = 4.0f;
                animation.KeyTimes = new NSNumber[] { 0.0f, 0.3f, 1.0f };
                animation.Values   = new NSObject[] {
                    NSValue.FromVector(new SCNVector4(0, 1, 0, 0)),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2)))
                };

                var timingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                animation.TimingFunctions = new CAMediaTimingFunction[] { timingFunction, timingFunction, timingFunction };
                animation.RepeatCount     = float.MaxValue;
                animation.BeginTime       = CAAnimation.CurrentMediaTime() + 1.0 + i * 0.2;            // desynchronize animations
                letterNode.AddAnimation(animation, new NSString("letterNodeAnimation"));
            }

            return(textNode);
        }
Example #24
0
        private void BuildImageGrid()
        {
            // Create a root node for the grid
            GroupNode = SCNNode.Create();

            // Retrieve the template node to replicate
            var scene        = SCNScene.FromFile("Contacts/contact");
            var templateNode = scene.RootNode.FindChildNode("people", true);

            for (int k = 0, j = 0; j < RowCount; j++)
            {
                for (var i = 0; i < ColumnCount; i++, k++)
                {
                    // Hierarchy : __groupNode > container > node
                    var container = SCNNode.Create();
                    var node      = templateNode.Clone();
                    node.Name = "contact" + k;

                    GroupNode.AddChildNode(container);
                    container.AddChildNode(node);

                    if (k == 28)
                    {
                        HeroNode = node;
                    }

                    // Curved layout
                    var angle = 0.12f * ((ColumnCount - 1) / 2.0f - i);
                    var x     = NMath.Cos(angle + (float)(Math.PI / 2)) * 500.0f;
                    var z     = NMath.Sin(angle + (float)(Math.PI / 2)) * 500.0f;
                    container.Position = new SCNVector3(x, j * 60, -z + 400);
                    container.Rotation = new SCNVector4(0, 1, 0, angle);

                    // We want a different image on each elemement and to do that we need to
                    // unshare the geometry first and then unshare the material

                    var geometryNode = node.ChildNodes [0];
                    geometryNode.Geometry = (SCNGeometry)geometryNode.Geometry.Copy();

                    var materialCopy = (SCNMaterial)geometryNode.Geometry.Materials [1].Copy();
                    materialCopy.Diffuse.Contents = new NSImage(NSBundle.MainBundle.PathForResource("Contacts/contact" + (k % ContactImageCount), "jpg"));
                    geometryNode.Geometry.ReplaceMaterial(1, materialCopy);

                    // Animate (rotate forever)
                    var animation = CAKeyFrameAnimation.GetFromKeyPath("rotation");
                    animation.Duration = 4.0f;
                    animation.KeyTimes = new NSNumber[] { 0.0f, 0.3f, 1.0f };
                    animation.Values   = new NSObject[] { NSValue.FromVector(new SCNVector4(0, 1, 0, 0)),
                                                          NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))),
                                                          NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2))) };

                    var tf = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                    animation.TimingFunctions = new CAMediaTimingFunction[] { tf, tf, tf };
                    animation.RepeatCount     = float.MaxValue;
                    animation.BeginTime       = CAAnimation.CurrentMediaTime() + 1.0f + j * 0.1f + i * 0.05f;                // desynchronize the animations
                    node.AddAnimation(animation, new NSString("animation"));
                }
            }

            // Add the group to the scene
            GroupNode.Scale    = new SCNVector3(0.03f, 0.03f, 0.03f);
            GroupNode.Position = new SCNVector3(0, Altitude - 2.8f, 18);
            GroupNode.Opacity  = 0.0f;

            GroundNode.AddChildNode(GroupNode);
        }
Example #25
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            switch (index)
            {
            case 0:
                // Set the slide's title and subtitle and add some text
                TextManager.SetTitle("Constraints");
                TextManager.SetSubtitle("SCNConstraint");

                TextManager.AddBulletAtLevel("Applied sequentially at render time", 0);
                TextManager.AddBulletAtLevel("Only affect presentation values", 0);

                TextManager.AddCode("#aNode.#Constraints# = new SCNConstraint[] { aConstraint, anotherConstraint, ... };#");

                // Tweak the near clipping plane of the spot light to get a precise shadow map
                presentationViewController.SpotLight.Light.SetAttribute(new NSNumber(10), SCNLightAttribute.ShadowNearClippingKey);
                break;

            case 1:
                // Remove previous text
                TextManager.FlipOutText(SlideTextManager.TextType.Subtitle);
                TextManager.FlipOutText(SlideTextManager.TextType.Bullet);
                TextManager.FlipOutText(SlideTextManager.TextType.Code);

                // Add new text
                TextManager.SetSubtitle("SCNLookAtConstraint");
                TextManager.AddBulletAtLevel("Makes a node to look at another node", 0);
                TextManager.AddCode("#nodeA.Constraints = new SCNConstraint[] { #SCNLookAtConstraint.Create# (nodeB) };#");

                TextManager.FlipInText(SlideTextManager.TextType.Subtitle);
                TextManager.FlipInText(SlideTextManager.TextType.Bullet);
                TextManager.FlipInText(SlideTextManager.TextType.Code);
                break;

            case 2:
                // Setup the scene
                SetupLookAtScene();

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                // Dim the text and move back a little bit
                TextManager.TextNode.Opacity = 0.5f;
                presentationViewController.CameraHandle.Position = presentationViewController.CameraNode.ConvertPositionToNode(new SCNVector3(0, 0, 5.0f), presentationViewController.CameraHandle.ParentNode);
                SCNTransaction.Commit();
                break;

            case 3:
                // Add constraints to the arrows
                var container = ContentNode.FindChildNode("arrowContainer", true);

                // "Look at" constraint
                var constraint = SCNLookAtConstraint.Create(BallNode);

                var i = 0;
                foreach (var arrow in container.ChildNodes)
                {
                    var delayInSeconds = 0.1 * i++;
                    var popTime        = new DispatchTime(DispatchTime.Now, (long)(delayInSeconds * Utils.NSEC_PER_SEC));
                    DispatchQueue.MainQueue.DispatchAfter(popTime, () => {
                        SCNTransaction.Begin();
                        SCNTransaction.AnimationDuration = 1;
                        // Animate to the result of applying the constraint
                        ((SCNNode)arrow.ChildNodes [0]).Rotation = new SCNVector4(0, 1, 0, (float)(Math.PI / 2));
                        arrow.Constraints = new SCNConstraint[] { constraint };
                        SCNTransaction.Commit();
                    });
                }
                break;

            case 4:
                // Create a keyframe animation to move the ball
                var animation = CAKeyFrameAnimation.GetFromKeyPath("position");
                animation.KeyTimes = new NSNumber[] {
                    0.0f,
                    (1.0f / 8.0f),
                    (2.0f / 8.0f),
                    (3.0f / 8.0f),
                    (4.0f / 8.0f),
                    (5.0f / 8.0f),
                    (6.0f / 8.0f),
                    (7.0f / 8.0f),
                    1.0f
                };

                animation.Values = new NSObject[] {
                    NSValue.FromVector(new SCNVector3(0, 0.0f, 0)),
                    NSValue.FromVector(new SCNVector3(20.0f, 0.0f, 20.0f)),
                    NSValue.FromVector(new SCNVector3(40.0f, 0.0f, 0)),
                    NSValue.FromVector(new SCNVector3(20.0f, 0.0f, -20.0f)),
                    NSValue.FromVector(new SCNVector3(0, 0.0f, 0)),
                    NSValue.FromVector(new SCNVector3(-20.0f, 0.0f, 20.0f)),
                    NSValue.FromVector(new SCNVector3(-40.0f, 0.0f, 0)),
                    NSValue.FromVector(new SCNVector3(-20.0f, 0.0f, -20.0f)),
                    NSValue.FromVector(new SCNVector3(0, 0.0f, 0))
                };

                animation.CalculationMode = CAKeyFrameAnimation.AnimationCubicPaced;                 // smooth the movement between keyframes
                animation.RepeatCount     = float.MaxValue;
                animation.Duration        = 10.0f;
                animation.TimingFunction  = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                BallNode.AddAnimation(animation, new NSString("ballNodeAnimation"));

                // Rotate the ball to give the illusion of a rolling ball
                // We need two animations to do that:
                // - one rotation to orient the ball in the right direction
                // - one rotation to spin the ball
                animation          = CAKeyFrameAnimation.GetFromKeyPath("rotation");
                animation.KeyTimes = new NSNumber[] {
                    0.0f,
                    (0.7f / 8.0f),
                    (1.0f / 8.0f),
                    (2.0f / 8.0f),
                    (3.0f / 8.0f),
                    (3.3f / 8.0f),
                    (4.7f / 8.0f),
                    (5.0f / 8.0f),
                    (6.0f / 8.0f),
                    (7.0f / 8.0f),
                    (7.3f / 8.0f),
                    1.0f
                };

                animation.Values = new NSObject[] {
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI / 4))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI / 4))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI / 2))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI + Math.PI / 2))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2 - Math.PI / 4))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2 - Math.PI / 4))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI * 2 - Math.PI / 2))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI - Math.PI / 2))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI / 4))),
                    NSValue.FromVector(new SCNVector4(0, 1, 0, (float)(Math.PI / 4)))
                };

                animation.RepeatCount    = float.MaxValue;
                animation.Duration       = 10.0f;
                animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                BallNode.AddAnimation(animation, new NSString("ballNodeAnimation2"));

                var rotationAnimation = CABasicAnimation.FromKeyPath("rotation");
                rotationAnimation.Duration    = 1.0f;
                rotationAnimation.RepeatCount = float.MaxValue;
                rotationAnimation.To          = NSValue.FromVector(new SCNVector4(1, 0, 0, (float)(Math.PI * 2)));
                BallNode.ChildNodes [1].AddAnimation(rotationAnimation, new NSString("ballNodeRotation"));
                break;

            case 5:
                // Add a constraint to the camera
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                constraint = SCNLookAtConstraint.Create(BallNode);
                presentationViewController.CameraNode.Constraints = new SCNConstraint[] { constraint };
                SCNTransaction.Commit();
                break;

            case 6:
                // Add a constraint to the light
                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 1;
                var cameraTarget = ContentNode.FindChildNode("cameraTarget", true);
                constraint = SCNLookAtConstraint.Create(cameraTarget);
                presentationViewController.SpotLight.Constraints = new SCNConstraint[] { constraint };
                SCNTransaction.Commit();
                break;
            }
        }