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");
            };
        }
        // 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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");
        }
Exemplo n.º 5
0
 protected CAKeyFrameAnimation CreateKeyFrame(string keyPath, string timingFuncName, params float[] values)
 {
     return(CAKeyFrameAnimation
            .FromKeyPath(keyPath)
            .SetTimingFunc((NSString)NSObject.FromObject(timingFuncName))        // CAMediaTimingFunction.Linear
            .SetValues(values));
 }
Exemplo n.º 6
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");
        }
Exemplo n.º 7
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");
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        private CAKeyFrameAnimation CreateTrackingAnimation(CGPath path)
        {
            var animation = CAKeyFrameAnimation.FromKeyPath("position");

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

            return(animation);
        }
Exemplo n.º 11
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");
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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;
 }
Exemplo n.º 14
0
        protected override void Prepare(UIView view)
        {
            view.Layer.AnchorPoint = new CoreGraphics.CGPoint(1, 1);

            var animationRotate = CAKeyFrameAnimation
                                  .FromKeyPath(TransformRotation)
                                  .SetValues(DegreesToRadians(-90), 0f);

            PlayTogether(
                CreateKeyFrame(Opacity, 0, 1),
                animationRotate);
        }
Exemplo n.º 15
0
        private CAKeyFrameAnimation CreateTrackingAnimation()
        {
            var start       = getStartingPoint();
            var endingPoint = getEndingPoint();

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

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

            return(animation);
        }
Exemplo n.º 16
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;
 }
        public static CAKeyFrameAnimation Path(UIBezierPath bezierPath, MaterialAnimationRotationMode mode = MaterialAnimationRotationMode.Auto, double?duration = null)
        {
            var animation = CAKeyFrameAnimation.FromKeyPath("position");

            animation.Path = bezierPath.CGPath;

            animation.RotationMode = Convert.MaterialAnimationRotationModeToValue(mode);
            if (duration != null)
            {
                animation.Duration = duration.Value;
            }
            return(animation);
        }
Exemplo n.º 18
0
        private void Close()
        {
            if (flag == -1)
            {
                this.isAnimating = false;
                this.timer.Invalidate();
                this.timer = null;
                return;
            }

            int      tag  = 1000 + flag;
            MenuItem item = this.GetByTag(tag);

            item.Selected -= this.ItemSelected;

            var rotateAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform.rotation.z");

            rotateAnimation.Values   = new NSNumber[] { 0f, this.CloseRotation, 0f };
            rotateAnimation.Duration = 0.5f;
            rotateAnimation.KeyTimes = new NSNumber[] { 0f, 0.4f, 0.5f };

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

            positionAnimation.Duration = 0.5f;

            var path = new CGPath();

            path.MoveToPoint(item.EndPoint.X, item.EndPoint.Y);
            path.AddLineToPoint(item.FarPoint.X, item.FarPoint.Y);
            path.AddLineToPoint(item.StartPoint.X, item.StartPoint.Y);
            positionAnimation.Path = path;

            var alphaAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("opacity");

            alphaAnimation.Values   = new NSNumber[] { 1f, 1f, 0f };
            alphaAnimation.Duration = 0.5f;
            alphaAnimation.KeyTimes = new NSNumber[] { 0f, 0.8f, 1f };

            var animationGroup = new CAAnimationGroup();

            animationGroup.Animations     = new[] { positionAnimation, rotateAnimation, alphaAnimation };
            animationGroup.Duration       = 0.5f;
            animationGroup.FillMode       = CAFillMode.Forwards;
            animationGroup.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);

            item.Layer.AddAnimation(animationGroup, "Close");

            item.Alpha  = 0f;
            item.Center = item.StartPoint;
            flag--;
        }
        /// <summary> Ò¡¶¯
        /// </summary>
        public void Shake()
        {
            CAKeyFrameAnimation kfa = CAKeyFrameAnimation.FromKeyPath(@"transform.translation.x");
            nfloat s = 5;

            //kfa.Values = "@[@(-s),@(0),@(s),@(0),@(-s),@(0),@(s),@(0)]";
            //ʱ³¤
            kfa.Duration = 0.3f;
            ////Öظ´
            kfa.RepeatCount = 2;
            ////ÒƳý
            kfa.RemovedOnCompletion = true;
            this.Layer.AddAnimation(kfa, @"shake");
        }
Exemplo n.º 20
0
        private void Expand()
        {
            if (flag == this.MenuItems.Count)
            {
                this.isAnimating = false;
                this.timer.Invalidate();
                this.timer = null;
                return;
            }

            int tag = 1000 + this.flag;

            MenuItem item = this.GetByTag(tag);

            item.Selected -= this.ItemSelected;
            item.Selected += this.ItemSelected;

            var rotateAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform.rotation.z");

            rotateAnimation.Values   = new NSNumber[] { this.ExpandRotation, 0.0f };
            rotateAnimation.Duration = 0.5f;
            rotateAnimation.KeyTimes = new NSNumber[] { 0.3f, 0.4f };

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

            positionAnimation.Duration = 0.5f;

            var path = new CGPath();

            path.MoveToPoint(item.StartPoint.X, item.StartPoint.Y);
            path.AddLineToPoint(item.FarPoint.X, item.FarPoint.Y);
            path.AddLineToPoint(item.NearPoint.X, item.NearPoint.Y);
            path.AddLineToPoint(item.EndPoint.X, item.EndPoint.Y);
            positionAnimation.Path = path;

            var animationGroup = new CAAnimationGroup();

            animationGroup.Animations     = new[] { positionAnimation, rotateAnimation };
            animationGroup.Duration       = 0.5f;
            animationGroup.FillMode       = CAFillMode.Forwards;
            animationGroup.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);

            item.Layer.AddAnimation(animationGroup, "Expand");

            item.Alpha  = 1f;
            item.Center = item.EndPoint;
            this.flag++;
        }
Exemplo n.º 21
0
        /// <summary> 摇动
        /// </summary>
        private void Shake()
        {
            CAKeyFrameAnimation kfa = CAKeyFrameAnimation.FromKeyPath(@"transform.translation.x");
            nfloat s = 5;

            NSObject[] ns = new NSObject[1];
            ns[0]      = FromObject("@[@(-s),@(0),@(s),@(0),@(-s),@(0),@(s),@(0)]");
            kfa.Values = ns;
            //时长
            kfa.Duration = 0.3f;
            ////重复
            kfa.RepeatCount = 2;
            ////移除
            kfa.RemovedOnCompletion = true;
            this.Layer.AddAnimation(kfa, @"shake");
        }
Exemplo n.º 22
0
        /* Animation engine to create a fill animation.
         * @param bounces The number of bounces for the animation.
         * @param amplitue How far does the animation bounce.
         * @param reserve Flag to track if the animation should fill or empty the layer.
         * @return Returns the CAKeyframeAnimation object.
         */
        public CAKeyFrameAnimation FillAnimationWithBounces(int bounces, float amplitude, bool reverse)
        {
            List <NSObject> values   = new List <NSObject>();
            List <NSNumber> keyTimes = new List <NSNumber>();

            if (reverse)
            {
                values.Add(NSValue.FromCATransform3D(CATransform3D.MakeScale(1, 1, 1)));
            }
            else
            {
                values.Add(NSValue.FromCATransform3D(CATransform3D.MakeScale(0, 0, 0)));
            }


            keyTimes.Add(new NSNumber(0));

            for (int i = 1; i <= bounces; i++)
            {
                var scale = (i % 2) > 0 ? (1 + amplitude / i) : (1 - amplitude / i);
                var time  = (float)(i * (1.0 / (bounces + 1)));
                values.Add(NSValue.FromCATransform3D(CATransform3D.MakeScale(scale, scale, scale)));
                keyTimes.Add(new NSNumber(time));
            }

            if (reverse)
            {
                values.Add(NSValue.FromCATransform3D(CATransform3D.MakeScale(new nfloat(0.0001), new nfloat(0.0001), new nfloat(0.0001))));
            }
            else
            {
                values.Add(NSValue.FromCATransform3D(CATransform3D.MakeScale(1, 1, 1)));
            }

            keyTimes.Add(new NSNumber(1));

            CAKeyFrameAnimation animation = CAKeyFrameAnimation.FromKeyPath("transform");

            animation.Values              = values.ToArray();
            animation.KeyTimes            = keyTimes.ToArray();
            animation.RemovedOnCompletion = false;
            animation.FillMode            = CAFillMode.Forwards;
            animation.Duration            = AnimationDuration;
            animation.TimingFunction      = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);

            return(animation);
        }
Exemplo n.º 23
0
        void DidTapMyLocation(object sender, EventArgs e)
        {
            var location = mapView.MyLocation;

            if (location == null || !location.Coordinate.IsValid())
            {
                return;
            }

            // Access the GMSMapLayer directly to modify the following properties with a
            // specified timing function and duration.

            var curve = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            CABasicAnimation animation;

            animation                = CABasicAnimation.FromKeyPath(Constants.LayerCameraLatitudeKey);
            animation.Duration       = 2.0;
            animation.TimingFunction = curve;
            animation.To             = NSNumber.FromDouble(location.Coordinate.Latitude);
            mapView.Layer.AddAnimation(animation, Constants.LayerCameraLatitudeKey);

            animation                = CABasicAnimation.FromKeyPath(Constants.LayerCameraLongitudeKey);
            animation.Duration       = 2.0;
            animation.TimingFunction = curve;
            animation.To             = NSNumber.FromDouble(location.Coordinate.Longitude);
            mapView.Layer.AddAnimation(animation, Constants.LayerCameraLongitudeKey);

            animation                = CABasicAnimation.FromKeyPath(Constants.LayerCameraBearingKey);
            animation.Duration       = 2.0;
            animation.TimingFunction = curve;
            animation.To             = NSNumber.FromDouble(0.0);
            mapView.Layer.AddAnimation(animation, Constants.LayerCameraBearingKey);

            // Fly out to the minimum zoom and then zoom back to the current zoom!
            var zoom      = mapView.Camera.Zoom;
            var keyValues = new [] {
                NSNumber.FromFloat(zoom),
                NSNumber.FromFloat(-100),
                NSNumber.FromFloat(zoom)
            };
            var keyFrameAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath(Constants.LayerCameraZoomLevelKey);

            keyFrameAnimation.Duration = 2.0;
            keyFrameAnimation.Values   = keyValues;
            mapView.Layer.AddAnimation(keyFrameAnimation, Constants.LayerCameraZoomLevelKey);
        }
        public static IDisposable RevealSwipeActionAnimation(this TimeEntriesLogViewCell cell, Direction direction)
        {
            if (cell == null)
            {
                return(Disposable.Empty);
            }

            var animation = CAKeyFrameAnimation.FromKeyPath("transform.translation.x");

            animation.Duration = 1.51;

            animation.TimingFunctions = new CAMediaTimingFunction[]
            {
                new CAMediaTimingFunction(1f, 1f, 1f, 1f),
                new CAMediaTimingFunction(.1f, .2f, .1f, 0f),
                new CAMediaTimingFunction(.1f, .1f, .1f, 0f),
                new CAMediaTimingFunction(.0f, .32f, .7f, 1f),
                new CAMediaTimingFunction(.38f, .1f, .7f, 1f),
                new CAMediaTimingFunction(1f, 1f, 1f, 1f)
            };

            animation.KeyTimes = new NSNumber[]
            {
                0.0,
                0.5,
                0.6,
                0.73,
                0.81,
                1.51
            };

            animation.Values = new[]
            {
                NSObject.FromObject(0.0),
                NSObject.FromObject((double)direction * 50.0),
                NSObject.FromObject(0.0),
                NSObject.FromObject((double)direction * 3.5),
                NSObject.FromObject(0.0),
                NSObject.FromObject(0.0)
            };

            animation.RepeatCount = int.MaxValue;
            cell.Layer.AddAnimation(animation, direction.ToString());

            return(animation);
        }
Exemplo n.º 25
0
        //Private methods
        private void Expand()
        {
            if (Flag == MenusArray.Count)
            {
                IsAnimating = flase;
                Timer.Invalidate();
                Timer = null;
                return;
            }

            var          Tag             = 1000 + Flag;
            ApexMenuItem item            = this.ViewWithTag(Tag);
            var          rotateAnimation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform.rotation.z");

            rotateAnimation.Values   = new NSNumber[] { this.ExpandRotation, 0.0f };
            rotateAnimation.Duration = AnimationDuration;
            rotateAnimation.KeyTimes = new NSNumber[] { 0.3f, 0.4f };

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

            positionAnimation.Duration = AnimationDuration;

            var path = new CGPath();

            path.MoveToPoint(item.StartPoint.X, item.StartPoint.Y);
            path.AddLineToPoint(item.FarPoint.X, item.FarPoint.Y);
            path.AddLineToPoint(item.NearPoint.X, item.NearPoint.Y);
            path.AddLineToPoint(item.EndPoint.X, item.EndPoint.Y);
            positionAnimation.Path = path;

            var animationGroup = new CAAnimationGroup();

            animationGroup.Animations     = new CAAnimation[] { positionAnimation, rotateAnimation };
            animationGroup.Duration       = AnimationDuration;
            animationGroup.FillMode       = CAFillMode.Forwards;
            animationGroup.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
            //animationgroup.delegate = self;

            if (Flag == MenusArray.Count - 1)
            {
                animationGroup.SetValueForKey("firstAnimation", "id");
            }
            item.Layer.AddAnimation(animationGroup, "Expand");
            item.Center = item.EndPoint;
            Flag++;
        }
Exemplo n.º 26
0
        CAAnimation MakeBounceAnimation(float offset, string key)
        {
            var animation = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath(key);

            animation.Duration = hideDelay;
            float left = offset / 2;

            animation.Values = new NSNumber [] {
                NSNumber.FromFloat(offset + left),
                //NSNumber.FromFloat (left-60),
                //NSNumber.FromFloat (left+40),
                NSNumber.FromFloat(left - 30),
                NSNumber.FromFloat(left + 10),
                NSNumber.FromFloat(left - 10),
                NSNumber.FromFloat(left),
            };

            return(animation);
        }
Exemplo n.º 27
0
        public static void ShakeVertically(this UIView view)
        {
            CAKeyFrameAnimation animation = CAKeyFrameAnimation.FromKeyPath("transform.translation.y");

            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
            animation.Duration       = 0.5;
            animation.Values         = new NSObject[]
            {
                NSNumber.FromFloat(-12),
                NSNumber.FromFloat(12),
                NSNumber.FromFloat(-8),
                NSNumber.FromFloat(8),
                NSNumber.FromFloat(-4),
                NSNumber.FromFloat(4),
                NSNumber.FromFloat(0)
            };

            view.Layer.AddAnimation(animation, "shake");
        }
Exemplo n.º 28
0
        public override void TouchesEnded(Foundation.NSSet touches, UIEvent evt)
        {
            base.TouchesEnded(touches, evt);

            //add layer with image and animate along path

            if (layer.SuperLayer == null)
            {
                Layer.AddSublayer(layer);
            }

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

            animPosition.Path     = path;
            animPosition.Duration = 3;
            layer.AddAnimation(animPosition, "position");
        }
        public static void ShakeVertically(this UIView view, float strength = 12.0f)
        {
            CAKeyFrameAnimation animation = CAKeyFrameAnimation.FromKeyPath("transform.translation.y");

            animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
            animation.Duration       = 0.5;
            animation.Values         = new NSObject[]
            {
                NSNumber.FromFloat(-strength),
                NSNumber.FromFloat(strength),
                NSNumber.FromFloat(-strength * 0.66f),
                NSNumber.FromFloat(strength * 0.66f),
                NSNumber.FromFloat(-strength * 0.33f),
                NSNumber.FromFloat(strength * 0.33f),
                NSNumber.FromFloat(0)
            };

            view.Layer.AddAnimation(animation, "shake");
        }
Exemplo n.º 30
0
 public static CAAnimation CreateDiscreteRotationAnimation()
 {
     var animation = CAKeyFrameAnimation.FromKeyPath("transform.rotation.z");
     {
         animation.Values = new NSObject[]
         {
             new NSNumber(0f),
             new NSNumber(1f * Math.PI / 6f),
             new NSNumber(2f * Math.PI / 6f),
             new NSNumber(3f * Math.PI / 6f),
             new NSNumber(4f * Math.PI / 6f),
             new NSNumber(5f * Math.PI / 6f),
             new NSNumber(6f * Math.PI / 6f),
             new NSNumber(7f * Math.PI / 6f),
             new NSNumber(8f * Math.PI / 6f),
             new NSNumber(9f * Math.PI / 6f),
             new NSNumber(10f * Math.PI / 6f),
             new NSNumber(11f * Math.PI / 6f),
             new NSNumber(2f * Math.PI)
         };
         animation.KeyTimes = new[]
         {
             new NSNumber(0f),
             new NSNumber(1f / 12f),
             new NSNumber(2f / 12f),
             new NSNumber(3f / 12f),
             new NSNumber(4f / 12f),
             new NSNumber(5f / 12f),
             new NSNumber(.5f),
             new NSNumber(7f / 12f),
             new NSNumber(8f / 12f),
             new NSNumber(9f / 12f),
             new NSNumber(10f / 12f),
             new NSNumber(11f / 12f),
             new NSNumber(1f)
         };
         animation.Duration = 1.2f;
         animation.CalculationMode = "discrete";
         animation.RepeatCount = float.MaxValue;
     }
     return animation;
 }