void AnimateMenu(MenuState newMenuState, float initialVelocity = 0.7f)
        {
            var initialVelocityVector = new CGVector(initialVelocity, 0f);
            var springParameters      = GetSpringTimingParameters(initialVelocityVector);
            var shouldMaximize        = newMenuState == MenuState.Open;

            menuAnimator = new UIViewPropertyAnimator(0, springParameters)
            {
                Interruptible = true,
            };

            menuAnimator.AddAnimations(() =>
            {
                menuViewController.View.Frame = new CGRect
                {
                    Location = new CGPoint
                    {
                        X = MenuDestinationXFromState(newMenuState),
                        Y = 0f,
                    },
                    Size = menuViewController.View.Frame.Size,
                };

                menuViewController.SetPercentMaximized(shouldMaximize ? 1 : 0);
                menuBackgroundView.Alpha = shouldMaximize ? 1 : 0;
            });

            menuAnimator.AddCompletion(pos => menuState = shouldMaximize ? MenuState.Open : MenuState.Closed);

            menuAnimator.StartAnimation();
        }
Exemple #2
0
    void Panned(NSObject r)
    {
        var recognizer = r as UIPanGestureRecognizer;
        var touchPoint = recognizer.LocationInView(View);

        switch (recognizer.State)
        {
        case UIGestureRecognizerState.Began:
            originalTouchPoint = touchPoint;
            break;

        case UIGestureRecognizerState.Changed:
            var offset = touchPoint.Y - originalTouchPoint.Y;
            offset = offset > 0 ? NMath.Pow(offset, 0.7f) : -NMath.Pow(-offset, 0.7f);
            rubberView.Transform = CGAffineTransform.MakeTranslation(0, offset);
            break;

        case UIGestureRecognizerState.Ended:
        case UIGestureRecognizerState.Cancelled:
            var timingParameters = UISpringTiming.MakeTimingParameters(damping: 0.6f, response: .3f);
            var animator         = new UIViewPropertyAnimator(duration: 0, parameters: timingParameters);
            animator.AddAnimations(() => rubberView.Transform = CGAffineTransform.MakeIdentity());
            animator.Interruptible = true;
            animator.StartAnimation();
            break;

        default:
            break;
        }
    }
Exemple #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            imageView       = new UIImageView(new CGRect(0, 100, 50, 50));
            image           = UIImage.FromFile("Sample.png");
            imageView.Image = image;
            imageView.Alpha = 0.25f;
            View.AddSubview(imageView);

            Action setCenterRight = () =>
            {
                var xpos = UIScreen.MainScreen.Bounds.Right - imageView.Frame.Width / 2;
                var ypos = imageView.Center.Y;
                imageView.Center = new CGPoint(xpos, ypos);
            };

            Action setCenterLeft = () =>
            {
                var xpos = UIScreen.MainScreen.Bounds.Left + imageView.Frame.Width / 2;
                var ypos = imageView.Center.Y;
                imageView.Center = new CGPoint(xpos, ypos);
            };

            Action setOpacity = () =>
            {
                imageView.Alpha = 1;
            };

            UIViewPropertyAnimator propertyAnimator = new UIViewPropertyAnimator(4, UIViewAnimationCurve.EaseInOut, setCenterRight);

            propertyAnimator.AddAnimations(setOpacity);

            Action <object> reversePosition = (o) =>
            {
                InvokeOnMainThread(() => {
                    propertyAnimator.AddAnimations(setCenterLeft);
                });
            };

            TimerCallback abortPositionDelegate = new TimerCallback(reversePosition);
            Timer         abortPosition         = new Timer(abortPositionDelegate, null, 3000, Timeout.Infinite);

            propertyAnimator.StartAnimation();
        }
Exemple #4
0
    void AnimateToRest()
    {
        var timingParameters = UISpringTiming.MakeTimingParameters(damping: 0.4f, response: 0.2f);
        var animator         = new UIViewPropertyAnimator(duration: 0, parameters: timingParameters);

        animator.AddAnimations(() => {
            Transform       = CGAffineTransform.MakeScale(1, 1);
            BackgroundColor = isOn ? onColor : offColor;
        });
        animator.Interruptible = true;
        animator.StartAnimation();
    }
Exemple #5
0
        public static void Animate(double duration, nfloat delay, CubicBezierCurve curve, Action changes, Action completion = null)
        {
            var propertyAnimator = new UIViewPropertyAnimator(duration, curve.ToCubicTimingParameters());

            propertyAnimator.AddAnimations(changes, delay);

            if (completion != null)
            {
                propertyAnimator.AddCompletion(_ => completion());
            }

            propertyAnimator.StartAnimation();
        }
Exemple #6
0
    void AnimateView()
    {
        var timingParameters = UISpringTiming.MakeTimingParameters(damping: dampingRatio, response: frequencyResponse);

        animator = new UIViewPropertyAnimator(duration: 0, parameters: timingParameters);
        animator.AddAnimations(() => {
            var translation = View.Bounds.Width - 2 * margin - 80;

            springView.Transform = CGAffineTransform.MakeTranslation(translation, 0);
        });
        animator.AddCompletion((x) => {
            springView.Transform = CGAffineTransform.MakeIdentity();
            AnimateView();
        });
        animator.StartAnimation();
    }
        void AnimatePullout(PulloutState newPulloutState, float initialVelocity = 0.7f, bool launchKeyboard = false)
        {
            var initialVelocityVector = new CGVector(0f, initialVelocity);

            var springParameters = GetSpringTimingParameters(initialVelocityVector);
            var destinationY     = PulloutDestinationYFromState(newPulloutState);

            pulloutAnimator = new UIViewPropertyAnimator(0, springParameters)
            {
                Interruptible = true,
            };

            pulloutAnimator.AddAnimations(() =>
            {
                mainPulloutView.Frame = new CGRect
                {
                    Location = new CGPoint
                    {
                        X = mainPulloutView.Frame.X,
                        Y = destinationY,
                    },
                    Size = mainPulloutView.Frame.Size,
                };

                mainPulloutView.SetPercentMaximized(newPulloutState == PulloutState.Maximized ? 1 : 0);
                mainPulloutView.SetPercentMinimized(newPulloutState == PulloutState.Neutral || newPulloutState == PulloutState.Maximized ? 0 : 1);

                pulloutBackgroundView.Alpha = newPulloutState == PulloutState.Maximized ? 1 : 0;
            });

            if (launchKeyboard)
            {
                mainPulloutView.LaunchKeyboard();
            }

            pulloutAnimator.AddCompletion(pos =>
            {
                pulloutState = newPulloutState;
                mainPulloutView.PulloutDidFinishAnimating(newPulloutState);
            });

            pulloutAnimator.StartAnimation();
        }
Exemple #8
0
    void Panned(NSObject r)
    {
        var recognizer = r as UIPanGestureRecognizer;
        var touchPoint = recognizer.LocationInView(View);
        var velocity   = recognizer.VelocityInView(View);

        switch (recognizer.State)
        {
        case UIGestureRecognizerState.Began:
            originalTouchPoint = touchPoint;
            break;

        case UIGestureRecognizerState.Changed:
            var offset = touchPoint.Y - originalTouchPoint.Y;
            if (offset > 0)
            {
                offset = NMath.Pow(offset, 0.7f);
            }
            else if (offset < -verticalOffset * 2)
            {
                offset = -verticalOffset * 2 - NMath.Pow(-(offset + verticalOffset * 2f), 0.7f);
            }
            accelerationView.Transform = CGAffineTransform.MakeTranslation(0, offset);
            TrackPause(velocity.Y, offset);
            break;

        case UIGestureRecognizerState.Ended:
        case UIGestureRecognizerState.Cancelled:
            var timingParameters = UISpringTiming.MakeTimingParameters(damping: 0.8f, response: 0.3f);
            var animator         = new UIViewPropertyAnimator(0, timingParameters);
            animator.AddAnimations(() => {
                accelerationView.Transform = CGAffineTransform.MakeIdentity();
                pauseLabel.Alpha           = 0;
            });
            animator.Interruptible = true;
            animator.StartAnimation();
            hasPaused = false;
            break;

        default:
            break;
        }
    }
    private void StartAnimationIfNeeded()
    {
        if (animator.Running)
        {
            return;
        }

        var timingParameters = UISpringTiming.MakeTimingParameters(damping: 1, response: 0.4f);

        animator = new UIViewPropertyAnimator(0, timingParameters);
        animator.AddAnimations(() => {
            momentumView.Transform = isOpen ? closedTransform : CGAffineTransform.MakeIdentity();
        });
        animator.AddCompletion((position) => {
            if (position == UIViewAnimatingPosition.End)
            {
                isOpen = !isOpen;
            }
        });

        animator.StartAnimation();
    }
Exemple #10
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            imageView       = new UIImageView(new CGRect(0, 100, 50, 50));
            image           = UIImage.FromBundle("Default.png");
            imageView.Image = image;
            imageView.Alpha = 0.25f;
            View.AddSubview(imageView);

            Action setCenterRight = () =>
            {
                var xpos = UIScreen.MainScreen.Bounds.Right - imageView.Frame.Width / 2;
                var ypos = imageView.Center.Y;
                imageView.Center = new CGPoint(xpos, ypos);
            };

            Action setCenterLeft = () =>
            {
                var xpos = UIScreen.MainScreen.Bounds.Left + imageView.Frame.Width / 2;
                var ypos = imageView.Center.Y;
                imageView.Center = new CGPoint(xpos, ypos);
            };

            Action setOpacity = () =>
            {
                imageView.Alpha = 1;
            };

            UIViewPropertyAnimator propertyAnimator = new UIViewPropertyAnimator(4, UIViewAnimationCurve.EaseInOut, setCenterRight);

            propertyAnimator.AddAnimations(setOpacity);

            Action <object> reversePosition = (o) =>
            {
                InvokeOnMainThread(() =>
                {
                    propertyAnimator.AddAnimations(setCenterLeft);
                });
            };

            TimerCallback abortPositionDelegate = new TimerCallback(reversePosition);
            Timer         abortPosition         = new Timer(abortPositionDelegate, null, 3000, Timeout.Infinite);

            propertyAnimator.StartAnimation();


            // Perform any additional setup after loading the view, typically from a nib.

            /*layer = new CALayer();
             * layer.Bounds = new CGRect(0, 0, 80, 80);
             * layer.Position = new CGPoint(100, 100);
             * layer.Contents = UIImage.FromBundle("Default.png").CGImage;
             * layer.ContentsGravity = CALayer.GravityResizeAspectFill;
             *
             * View.Layer.AddSublayer(layer);
             *
             * /*UIImageView imageView= new UIImageView(new CGRect(50, 50, 57, 57));
             * UIImage image = UIImage.FromBundle("Default.png");
             * imageView.Image = image;
             * View.AddSubview(imageView);
             *
             * CGPoint point = imageView.Center;
             * UIView.Animate(2, 0, UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.Autoreverse,
             *  () =>
             *  {
             *      imageView.Center = new CGPoint(UIScreen.MainScreen.Bounds.Right - imageView.Frame.Width / 2, imageView.Center.Y);
             *  },
             *  () =>
             *  {
             *      imageView.Center = point;
             *  }
             * );*/
        }