void UpdateRecordButton(bool isRecording)
        {
            //Corner Radius
            var radiusAnimation = CABasicAnimation.FromKeyPath("cornerRadius");

            radiusAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
            radiusAnimation.From           = NSNumber.FromNFloat(recordButton.Layer.CornerRadius);

            //Border Thickness
            var borderAnimation = CABasicAnimation.FromKeyPath("borderWidth");

            borderAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseIn);
            radiusAnimation.From           = NSNumber.FromNFloat(recordButton.Layer.BorderWidth);

            //Animation Group
            var animationGroup = CAAnimationGroup.CreateAnimation();

            animationGroup.Animations = new CAAnimation[] { radiusAnimation, borderAnimation };
            animationGroup.Duration   = 0.6;
            animationGroup.FillMode   = CAFillMode.Forwards;

            recordButton.Layer.CornerRadius = isRecording ? 4 : recordButton.Frame.Width / 2;
            recordButton.Layer.BorderWidth  = isRecording ? 2 : 3;

            recordButton.Layer.AddAnimation(animationGroup, "borderChanges");
        }
示例#2
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);
        }
        void MoveLogoToTopLeft()
        {
            if (Cancelled)
            {
                return;
            }

            var rotate = CABasicAnimation.FromKeyPath("transform.rotation");

            rotate.From = NSObject.FromObject(0);
            rotate.To   = NSObject.FromObject(Math.PI * 2);

            var liftAndSlide = CABasicAnimation.FromKeyPath("position");

            liftAndSlide.From = NSValue.FromCGPoint(SlinkLogoImageView.Layer.Position);
            liftAndSlide.To   = NSValue.FromCGPoint(new CGPoint(40, 75));

            var shrink = CABasicAnimation.FromKeyPath("transform.scale");

            shrink.To = NSNumber.FromDouble(0.5);

            var animationGroup = CAAnimationGroup.CreateAnimation();

            animationGroup.Animations          = new CAAnimation[] { rotate, liftAndSlide, shrink };
            animationGroup.Duration            = animationDuration / 2;
            animationGroup.FillMode            = CAFillMode.Forwards;
            animationGroup.RemovedOnCompletion = false;
            rotate.RepeatCount = 0;

            SlinkLogoImageView.Layer.AddAnimation(animationGroup, "MoveLogoToTopLeft");
        }
        private void Animate()
        {
            if (stopAnim)
            {
                return;
            }

            if (locationAnimations != null)
            {
                AnimationImage.Layer.RemoveAnimation("locAnim");
            }

            var locationAnimation = CABasicAnimation.FromKeyPath("opacity");

            locationAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            locationAnimation.From           = NSNumber.FromFloat(GetAlpha());
            locationAnimation.To             = NSNumber.FromFloat(0.05f);

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

            scaleAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
            scaleAnimation.From           = NSNumber.FromFloat(1.1f);
            scaleAnimation.To             = NSNumber.FromFloat(1);;

            locationAnimations                   = CAAnimationGroup.CreateAnimation();
            locationAnimations.Duration          = GetAnimationDuration();
            locationAnimations.AutoReverses      = true;
            locationAnimations.Animations        = new CAAnimation[] { scaleAnimation, locationAnimation };
            locationAnimations.AnimationStopped += (sender, e) => {
                Animate();
            };

            AnimationImage.Layer.AddAnimation(locationAnimations, "locAnim");
            systemSound.PlaySystemSound();
        }
示例#5
0
        CAAnimation CreateMoveAndGrowAnimation(CALayer progress, double growToFraction)
        {
            CAAnimationGroup grp = CAAnimationGroup.CreateAnimation();

            grp.Duration            = 0.2;
            grp.FillMode            = CAFillMode.Forwards;
            grp.RemovedOnCompletion = false;

            CABasicAnimation move      = CABasicAnimation.FromKeyPath("position.x");
            double           oldOffset = (progress.Frame.Width / 2) * oldFraction;
            double           newOffset = (progress.Frame.Width / 2) * growToFraction;

            move.From = NSNumber.FromDouble(oldOffset);
            move.To   = NSNumber.FromDouble(newOffset);

            CABasicAnimation grow = CABasicAnimation.FromKeyPath("bounds");

            grow.From      = NSValue.FromCGRect(new CGRect(0, 0, progress.Frame.Width * (nfloat)oldFraction, barHeight));
            grow.To        = NSValue.FromCGRect(new CGRect(0, 0, progress.Frame.Width * (nfloat)growToFraction, barHeight));
            grp.Animations = new [] {
                move,
                grow,
            };
            return(grp);
        }
示例#6
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);
        }
示例#7
0
 public BaseViewAnimator()
 {
     AnimatorAgent = CAAnimationGroup.CreateAnimation();
     AnimatorAgent.AnimationStarted += (sender, e) => { };
     AnimatorAgent.AnimationStopped += (sender, e) =>
     {
         tcs?.SetResult(true);
     };
 }
示例#8
0
        private CAAnimationGroup GroupAnimation(RectangleF frame)
        {
            CAAnimationGroup animationGroup = CAAnimationGroup.CreateAnimation();

            animationGroup.Animations = new CAAnimation[] { frameAnimation(frame),
                                                            rotationAnimation() };
            animationGroup.Duration     = 1;
            animationGroup.AutoReverses = true;
            return(animationGroup);
        }
示例#9
0
        private void ExtractAnimation(SCNSceneSource sceneSource)
        {
            // In this scene objects are animated separately using long animations
            // playing 3 successive animations. We will group these long animations
            // and then split the group in 3 different animation groups.
            // We could also have used three DAEs (one per animation).

            var animationIDs = sceneSource.GetIdentifiersOfEntries(new Class("CAAnimation"));

            var animationCount = animationIDs.Length;
            var longAnimations = new CAAnimation [animationCount];

            var maxDuration = 0.0;

            for (var index = 0; index < animationCount; index++)
            {
                var animation = (CAAnimation)sceneSource.GetEntryWithIdentifier(animationIDs [index].ToString(), new Class("CAAnimation"));
                if (animation != null)
                {
                    maxDuration            = Math.Max(maxDuration, animation.Duration);
                    longAnimations [index] = animation;
                }
            }

            var longAnimationsGroup = new CAAnimationGroup();

            longAnimationsGroup.Animations = longAnimations;
            longAnimationsGroup.Duration   = maxDuration;

            var idleAnimationGroup = (CAAnimationGroup)longAnimationsGroup.Copy();

            idleAnimationGroup.TimeOffset   = 6.45833333333333f;
            IdleAnimationGroup              = CAAnimationGroup.CreateAnimation();
            IdleAnimationGroup.Animations   = new CAAnimation[] { idleAnimationGroup };
            IdleAnimationGroup.Duration     = 24.71f - 6.45833333333333f;
            IdleAnimationGroup.RepeatCount  = float.MaxValue;
            IdleAnimationGroup.AutoReverses = true;

            var animationGroup1 = (CAAnimationGroup)longAnimationsGroup.Copy();

            AnimationGroup1                 = CAAnimationGroup.CreateAnimation();
            AnimationGroup1.Animations      = new CAAnimation[] { animationGroup1 };
            AnimationGroup1.Duration        = 1.4f;
            AnimationGroup1.FadeInDuration  = 0.1f;
            AnimationGroup1.FadeOutDuration = 0.5f;

            var animationGroup2 = (CAAnimationGroup)longAnimationsGroup.Copy();

            animationGroup2.TimeOffset      = 3.666666666666667f;
            AnimationGroup2                 = CAAnimationGroup.CreateAnimation();
            AnimationGroup2.Animations      = new CAAnimation[] { animationGroup2 };
            AnimationGroup2.Duration        = 6.416666666666667f - 3.666666666666667f;
            AnimationGroup2.FadeInDuration  = 0.1f;
            AnimationGroup2.FadeOutDuration = 0.5f;
        }
        /// <summary>
        /// Shows the complete screen.
        /// </summary>
        /// <param name="message">Message to display</param>
        /// <param name="wasSuccessful">If set to <c>true</c> was process successful.</param>
        public void ShowCompleteScreen(string message, bool wasSuccessful)
        {
            var image = (wasSuccessful) ? UIImage.FromBundle("CallbackSuccess") : UIImage.FromBundle("CallbackWrong");

            CallbackIcon.Image   = image;
            CallbackMessage.Text = message;

            UIView.AnimateNotify(0.3f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () => { CallbackMessage.Alpha = 1.0f; }, (finished) => {});
            UIView.AnimateNotify(0.3f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () => { CallbackIcon.Alpha = 1.0f; }, (finished) => {});

            var ButtonScaleKeepCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            ButtonScaleKeepCABasicAnimation.Duration            = 2.0f;
            ButtonScaleKeepCABasicAnimation.AutoReverses        = false;
            ButtonScaleKeepCABasicAnimation.From                = NSNumber.FromNFloat(FullPara);
            ButtonScaleKeepCABasicAnimation.To                  = NSNumber.FromNFloat(FullPara);
            ButtonScaleKeepCABasicAnimation.FillMode            = CAFillMode.Forwards;
            ButtonScaleKeepCABasicAnimation.RemovedOnCompletion = false;
            ButtonScaleKeepCABasicAnimation.BeginTime           = 0.0f;

            var ButtonScaleSmallCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            ButtonScaleSmallCABasicAnimation.Duration            = 0.2f;
            ButtonScaleSmallCABasicAnimation.AutoReverses        = false;
            ButtonScaleSmallCABasicAnimation.From                = NSNumber.FromNFloat(FullPara);
            ButtonScaleSmallCABasicAnimation.To                  = NSNumber.FromDouble(SmallPara);
            ButtonScaleSmallCABasicAnimation.FillMode            = CAFillMode.Forwards;
            ButtonScaleSmallCABasicAnimation.RemovedOnCompletion = false;
            ButtonScaleSmallCABasicAnimation.BeginTime           = 2.0f;

            SmallButton.Layer.AddAnimation(ButtonScaleSmallCABasicAnimation, @"ButtonScaleAnimation");

            var animGroup = CAAnimationGroup.CreateAnimation();

            animGroup.Animations          = new CAAnimation[] { ButtonScaleKeepCABasicAnimation, ButtonScaleSmallCABasicAnimation };
            animGroup.Duration            = 2.2f;
            animGroup.RemovedOnCompletion = false;
            animGroup.AutoReverses        = false;
            animGroup.FillMode            = CAFillMode.Forwards;


            CATransaction.Begin();

            CATransaction.CompletionBlock = () => {
                UIView.AnimateNotify(0.1f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () => { CallbackIcon.Alpha = 0.0f; }, (finished) => {});
                UIView.AnimateNotify(0.1f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () => { CallbackMessage.Alpha = 0.0f; }, (finished) => {});

                SmallButton.SetImage(IconImage, UIControlState.Normal);

                UIView.AnimateNotify(0.1f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () => { SmallButton.ImageView.Alpha = 1.0f; }, (finished) => {});
            };

            SmallButton.Layer.AddAnimation(animGroup, @"ButtonScaleAnimation");
            CATransaction.Commit();
        }
示例#11
0
        CAAnimation CreateMoveAndGrowAnimation(CALayer progress, double growToFraction)
        {
            CAAnimationGroup grp = CAAnimationGroup.CreateAnimation();

            grp.Duration            = 0.2;
            grp.FillMode            = CAFillMode.Forwards;
            grp.RemovedOnCompletion = false;

            CABasicAnimation grow = CABasicAnimation.FromKeyPath("bounds");

            grow.From      = NSValue.FromCGRect(new CGRect(0, 0, Frame.Width * (nfloat)oldFraction, barHeight));
            grow.To        = NSValue.FromCGRect(new CGRect(0, 0, Frame.Width * (nfloat)growToFraction, barHeight));
            grp.Animations = new [] {
                grow,
            };
            return(grp);
        }
        void MoveCardBetweenPhones(UIView card, double duration, CGPoint destination)
        {
            if (Cancelled)
            {
                return;
            }

            var rotate = CABasicAnimation.FromKeyPath("transform.rotation");

            rotate.From = NSObject.FromObject(0);
            rotate.To   = NSObject.FromObject(Math.PI * 2);

            var liftAndSlideRight = CABasicAnimation.FromKeyPath("position");

            liftAndSlideRight.To = NSValue.FromCGPoint(destination);
            liftAndSlideRight.RemovedOnCompletion = false;
            liftAndSlideRight.FillMode            = CAFillMode.Forwards;

            var grow = CABasicAnimation.FromKeyPath("transform.scale");

            grow.To                  = NSNumber.FromDouble(7.5);
            grow.Duration            = animationDuration / 2;
            grow.RemovedOnCompletion = false;
            grow.FillMode            = CAFillMode.Forwards;

            var shrink = CABasicAnimation.FromKeyPath("transform.scale");

            shrink.To                  = NSNumber.FromDouble(3.0);
            shrink.BeginTime           = animationDuration / 2;
            shrink.RemovedOnCompletion = false;
            shrink.FillMode            = CAFillMode.Forwards;

            var animationGroup = CAAnimationGroup.CreateAnimation();

            animationGroup.Animations          = new CAAnimation[] { rotate, liftAndSlideRight, grow, shrink };
            animationGroup.Duration            = duration;
            animationGroup.FillMode            = CAFillMode.Forwards;
            animationGroup.RemovedOnCompletion = false;
            rotate.RepeatCount = 0;

            card.Layer.AddAnimation(animationGroup, "MoveCardBetweenPhones");
        }
        void initButtons()
        {
            var moveBtn = UIButton.FromType(UIButtonType.RoundedRect);

            moveBtn.Frame = new RectangleF(View.Bounds.Width - 240, 60, 200, 40);
            moveBtn.SetTitle("Move X", UIControlState.Normal);
            moveBtn.TouchUpInside += (object sender, EventArgs e) => {
                if (logoView.Layer.PresentationLayer.Position.X < 400)
                {
                    Rouse.To(logoView, 1, new RouseLib.KeyPaths {
                        PositionX = 400
                    }, Easing.EaseInExpo);

//					Rouse.To (logoLayer, 1, new RouseLib.KeyPaths{ PositionX = 400}, Easing.EaseInExpo);
                    var localTime = CAAnimation.CurrentMediaTime();

                    var ka = new CAKeyFrameAnimation();
                    ka.KeyPath        = "position.x";
                    ka.BeginTime      = 0;
                    ka.Duration       = 1;
                    ka.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                    ka.Values         = KeyFrameUtils.CreateKeyValues(logoLayer.Position.X, 400f, RouseLib.Easing.EaseInExpo);

//					var ka2 = new CAKeyFrameAnimation ();
//					ka2.KeyPath = "opacity";
//					ka2.BeginTime = 0;
//					ka2.Duration = 1;
//					ka2.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.Linear);
//					ka2.Values = KeyFrameUtils.CreateKeyValues (1, 0.2f, RouseLib.Easing.EaseInExpo);
//
                    var group = CAAnimationGroup.CreateAnimation();
                    group.BeginTime           = localTime;
                    group.Duration            = 1;
                    group.FillMode            = CAFillMode.Forwards;
                    group.RemovedOnCompletion = false;
                    group.Animations          = new CAAnimation[] { ka };
                    logoLayer.AddAnimation(group, null);
                }
                else
                {
                    Rouse.To(logoView, 1, new RouseLib.KeyPaths {
                        PositionX = 70
                    }, Easing.EaseOutExpo);

//					Rouse.To (logoLayer, 1, new RouseLib.KeyPaths{ PositionX = 70}, Easing.EaseOutExpo);
                    var localTime = CAAnimation.CurrentMediaTime();

                    var ka = new CAKeyFrameAnimation();
                    ka.KeyPath        = "position.x";
                    ka.BeginTime      = 0;
                    ka.Duration       = 1;
                    ka.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                    ka.Values         = KeyFrameUtils.CreateKeyValues(logoLayer.PresentationLayer.Position.X, 70f, RouseLib.Easing.EaseOutExpo);

                    //					var ka2 = new CAKeyFrameAnimation ();
                    //					ka2.KeyPath = "opacity";
                    //					ka2.BeginTime = 0;
                    //					ka2.Duration = 1;
                    //					ka2.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.Linear);
                    //					ka2.Values = KeyFrameUtils.CreateKeyValues (1, 0.2f, RouseLib.Easing.EaseInExpo);
                    //
                    var group = CAAnimationGroup.CreateAnimation();
                    group.BeginTime           = localTime;
                    group.Duration            = 1;
                    group.FillMode            = CAFillMode.Forwards;
                    group.RemovedOnCompletion = false;
                    group.Animations          = new CAAnimation[] { ka };
                    logoLayer.AddAnimation(group, null);
                }
            };
            View.AddSubview(moveBtn);
        }
        /// <summary>
        /// Touchs up inside animation.
        /// </summary>
        public void TouchUpInsideAnimation()
        {
            this.IsPerformingTouchUpInsideAnimation = true;

            foreach (UIImageView Icon in IconArray)
            {
                UIView.AnimateNotify(0.1f, 0.0f, UIViewAnimationOptions.BeginFromCurrentState, () =>
                {
                    Icon.Alpha = 0.0f;
                }, (finished) =>
                {
                    if (finished)
                    {
                        Icon.Hidden = true;
                    }
                });
            }

            var BackgroundViewScaleSmallCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            BackgroundViewScaleSmallCABasicAnimation.Duration            = 0.1f;
            BackgroundViewScaleSmallCABasicAnimation.AutoReverses        = false;
            BackgroundViewScaleSmallCABasicAnimation.To                  = NSNumber.FromDouble(SmallPara);
            BackgroundViewScaleSmallCABasicAnimation.From                = NSNumber.FromDouble(MidiumPara);
            BackgroundViewScaleSmallCABasicAnimation.FillMode            = CAFillMode.Forwards;
            BackgroundViewScaleSmallCABasicAnimation.RemovedOnCompletion = false;
            BackgroundViewScaleSmallCABasicAnimation.BeginTime           = 0.0f;

            BackgroundView.Layer.AddAnimation(BackgroundViewScaleSmallCABasicAnimation, @"BackgroundViewScaleSmallCABasicAnimation");

            var ButtonScaleFullCABasicAnimation = CABasicAnimation.FromKeyPath(@"transform.scale");

            ButtonScaleFullCABasicAnimation.Duration            = 0.2f;
            ButtonScaleFullCABasicAnimation.AutoReverses        = false;
            ButtonScaleFullCABasicAnimation.To                  = NSNumber.FromNFloat(FullPara);
            ButtonScaleFullCABasicAnimation.From                = NSNumber.FromDouble(MidiumPara);
            ButtonScaleFullCABasicAnimation.FillMode            = CAFillMode.Forwards;
            ButtonScaleFullCABasicAnimation.RemovedOnCompletion = false;
            ButtonScaleFullCABasicAnimation.BeginTime           = 0.0f;

            var animGroup = CAAnimationGroup.CreateAnimation();

            animGroup.Animations          = new CAAnimation[] { ButtonScaleFullCABasicAnimation };
            animGroup.Duration            = 0.4f;
            animGroup.RemovedOnCompletion = false;
            animGroup.AutoReverses        = false;
            animGroup.FillMode            = CAFillMode.Forwards;

            CATransaction.Begin();
            CATransaction.CompletionBlock = () => {
                IsPerformingTouchUpInsideAnimation = false;
            };

            SmallButton.Layer.AddAnimation(animGroup, @"ButtonScaleAnimation");
            CATransaction.Commit();


            CATransform3D Rotate = CATransform3D.MakeRotation(0, 0, 1, 0).Concat(CATransform3D.MakeRotation(0, 1, 0, 0));

            if (Parallex)
            {
                SmallButton.Layer.Transform = CATransform3DPerspect(Rotate, new CGPoint(0, 0), BigRadius + ParallexParameter);
            }
            else
            {
                //Do nothing ^_^
            }
        }
示例#15
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            base.ViewDidLoad();

            #region "Capa Imagen 1"
            CapaImagen1          = new CALayer();
            CapaImagen1.Bounds   = new CGRect(0, 0, 100, 100);
            CapaImagen1.Position = new CGPoint(50, 100);
            CapaImagen1.Contents = UIImage.FromFile
                                       ("foto1.jpg").CGImage;
            CapaImagen1.ContentsGravity = CALayer.
                                          GravityResizeAspectFill;

            #region "Rotació Imagen 1"
            CapaImagen1.Transform = CATransform3D.
                                    MakeRotation((float)Math.PI * 2, 0, 0, 1);
            CAKeyFrameAnimation Rotacion1 =
                (CAKeyFrameAnimation)
                CAKeyFrameAnimation.FromKeyPath("transform");
            Rotacion1.Values = new NSObject[] {
                NSNumber.FromFloat(0f),
                NSNumber.FromFloat((float)Math.PI / 2f),
                NSNumber.FromFloat((float)Math.PI),
                NSNumber.FromFloat((float)Math.PI * 2)
            };
            Rotacion1.ValueFunction = CAValueFunction.
                                      FromName(CAValueFunction.RotateZ);
            Rotacion1.Duration = 5;
            CapaImagen1.AddAnimation(Rotacion1, "transform");
            #endregion
            #endregion


            #region "Capa Imagen 3"
            CapaImagen3                 = new CALayer();
            CapaImagen3.Bounds          = new CGRect(0, 0, 100, 100);
            CapaImagen3.Position        = new CGPoint(50, 500);
            CapaImagen3.Contents        = UIImage.FromFile("foto1.jpg").CGImage;
            CapaImagen3.ContentsGravity = CALayer.GravityResizeAspectFill;

            #region "Animació Imagen 3"
            var OrigenImagen3 = CapaImagen3.Position;
            CapaImagen3.Position = new CGPoint(290, 100);
            var Animacion3 = CABasicAnimation.FromKeyPath("position");
            Animacion3.TimingFunction = CAMediaTimingFunction.FromName
                                            (CAMediaTimingFunction.EaseInEaseOut);
            Animacion3.From = NSValue.FromCGPoint(OrigenImagen3);
            Animacion3.To   = NSValue.FromCGPoint(new CGPoint(290, 100));
            #endregion

            #region "Rotació Imagen 3"
            CapaImagen3.Transform = CATransform3D.
                                    MakeRotation((float)Math.PI * 2, 0, 0, 1);
            var Rotacion2 = (CAKeyFrameAnimation)
                            CAKeyFrameAnimation.FromKeyPath("transform");
            Rotacion2.Values = new NSObject[] {
                NSNumber.FromFloat(0f),
                NSNumber.FromFloat((float)Math.PI / 2f),
                NSNumber.FromFloat((float)Math.PI),
                NSNumber.FromFloat((float)Math.PI * 2)
            };
            Rotacion2.ValueFunction = CAValueFunction.FromName(CAValueFunction.RotateY);
            #endregion

            #region "Agregar Animació y Rotació a la Capa 3"
            var ConjuntodeAnimacion = CAAnimationGroup.CreateAnimation();
            ConjuntodeAnimacion.Duration   = 2;
            ConjuntodeAnimacion.Animations = new CAAnimation[]
            { Animacion3, Rotacion2 };
            CapaImagen3.AddAnimation(ConjuntodeAnimacion, null);
            #endregion
            #endregion

            //wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
            #region "Capa Imagen 4"
            capaImagen4                 = new CALayer();
            capaImagen4.Bounds          = new CGRect(0, 0, 100, 100);
            capaImagen4.Position        = new CGPoint(300, 500);
            capaImagen4.Contents        = UIImage.FromFile("foto1.jpg").CGImage;
            capaImagen4.ContentsGravity = CALayer.GravityResizeAspectFill;

            #region "Animació Imagen 4"
            var OrigenImagen4 = capaImagen4.Position;
            capaImagen4.Position = new CGPoint(38, 100);
            var Animacion4 = CABasicAnimation.FromKeyPath("position");
            Animacion4.TimingFunction = CAMediaTimingFunction.FromName
                                            (CAMediaTimingFunction.EaseInEaseOut);
            Animacion4.From = NSValue.FromCGPoint(OrigenImagen4);
            Animacion4.To   = NSValue.FromCGPoint(new CGPoint(38, 100));
            #endregion

            #region "Rotació Imagen 3"
            capaImagen4.Transform = CATransform3D.
                                    MakeRotation((float)Math.PI * 2, 0, 0, 1);
            var Rotacion3 = (CAKeyFrameAnimation)
                            CAKeyFrameAnimation.FromKeyPath("transform");
            Rotacion3.Values = new NSObject[] {
                NSNumber.FromFloat(0f),
                NSNumber.FromFloat((float)Math.PI / 2f),
                NSNumber.FromFloat((float)Math.PI),
                NSNumber.FromFloat((float)Math.PI * 2)
            };
            Rotacion3.ValueFunction = CAValueFunction.FromName(CAValueFunction.RotateY);
            #endregion

            #region "Agregar Animació y Rotació a la Capa 3"
            var ConjuntodeAnimacion1 = CAAnimationGroup.CreateAnimation();
            ConjuntodeAnimacion1.Duration   = 2;
            ConjuntodeAnimacion1.Animations = new CAAnimation[]
            { Animacion4, Rotacion3 };
            capaImagen4.AddAnimation(ConjuntodeAnimacion1, null);
            #endregion
            #endregion


            View.Layer.AddSublayer(CapaImagen3);
            View.Layer.AddSublayer(capaImagen4);
        }
示例#16
0
    public static void To(object target,
                          float duration,
                          KeyPaths properties,
                          object options,
                          EasingFormula easing,
                          Action onComplete)
    {
        CALayer layer;

        if (TypeUtils.IsUIView(target))
        {
            layer = (target as UIView).Layer;
        }
        else
        {
            layer = target as CALayer;
        }

//		layer.RemoveAllAnimations(); // kill any previous animations hanging around

        if (easing == null)
        {
            easing = Easing.EaseInSine;
        }

        var animations = new List <CAKeyFrameAnimation>();
        var propType   = properties.GetType();

        foreach (var field in propType.GetFields(BindingFlags.Instance |
                                                 BindingFlags.NonPublic |
                                                 BindingFlags.Public))
        {
            if (field.GetValue(properties) != null)
            {
                var ka = new CAKeyFrameAnimation();
                ka.KeyPath        = LayerUtils.GetKeyPath(field.Name);
                ka.BeginTime      = 0;
                ka.Duration       = duration;
                ka.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);

                var fromValue = LayerUtils.GetCurrentValue(layer, field.Name);
                var toValue   = Convert.ToSingle(field.GetValue(properties));
                ka.Values = KeyFrameUtils.CreateKeyValues((float)fromValue, (float)toValue, easing);

                if (TypeUtils.IsUIView(target))
                {
                    setLayerProperties(layer, field.Name, toValue);
                }

                animations.Add(ka);
            }
        }

        var localTime = CAAnimation.CurrentMediaTime();
        var group     = CAAnimationGroup.CreateAnimation();

        group.BeginTime           = localTime; // TODO + delay from options...
        group.Duration            = duration;
        group.FillMode            = CAFillMode.Forwards;
        group.RemovedOnCompletion = false;
        //		group.AutoReverses = false;
        //		group.RepeatCount = 0;

        if (onComplete != null)
        {
            group.AnimationStopped += (object sender, CAAnimationStateEventArgs e) => {
                onComplete.Invoke();
            };
        }

        group.Animations = animations.ToArray();
        layer.AddAnimation(group, null);
    }
示例#17
0
            internal SwipeMenuView(BaseTimelineViewController parent, UIImage [] images, RectangleF frame) : base(frame)
            {
                this.parent = parent;
                this.images = images;

                Layer.MasksToBounds = true;
                Layer.AddSublayer(MakeBackgroundLayer(frame));

                layers = new CALayer [images.Length];

                float  slotsize = frame.Width / layers.Length;
                double delay    = globalDelay;

                for (int i = 0; i < layers.Length; i++)
                {
                    var image = images [i];
                    var layer = layers [i] = new CALayer();
                    Graphics.ConfigLayerHighRes(layer);

                    image          = RenderImageWithShadow(image, 3, UIColor.Black);
                    layer.Contents = image.CGImage;

                    var alpha = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("opacity");
#if false
                    var vals = new List <NSNumber> ();
                    for (int j = 0; j <= i; j++)
                    {
                        vals.Add(new NSNumber(0));
                    }
                    vals.Add(new NSNumber(1));
                    alpha.Values = vals.ToArray();
#endif
                    alpha.Values = new NSNumber [] {
                        NSNumber.FromFloat(0),
                        NSNumber.FromFloat(0.1f),
                        NSNumber.FromFloat(1),
                    };
                    alpha.KeyTimes = new NSNumber [] {
                        NSNumber.FromFloat(0),
                        NSNumber.FromFloat(1f / (layers.Length - i)),
                        NSNumber.FromFloat(1),
                    };

                    var size = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("transform.scale");
                    size.Values = new NSNumber [] {
                        NSNumber.FromFloat(0.7f),
                        NSNumber.FromFloat(1.3f),
                        NSNumber.FromFloat(1),
                    };

#if debug
                    var pos = (CAKeyFrameAnimation)CAKeyFrameAnimation.FromKeyPath("position.y");
                    pos.Values = new NSNumber [] {
                        NSNumber.FromFloat(0f),
                        NSNumber.FromFloat(60f),
                    };
#endif
                    var group = CAAnimationGroup.CreateAnimation();
                    group.Animations = new CAAnimation [] { alpha, size /*, pos */ };
                    group.Duration   = delay;

                    layer.AddAnimation(group, "showup");

                    layer.Frame = new RectangleF(
                        (int)(slotsize * i + image.Size.Width / 2),
                        (int)(frame.Height - image.Size.Height) / 2,
                        image.Size.Width, image.Size.Height);

                    Layer.AddSublayer(layer);
                }
            }