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();
        }
Beispiel #2
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();
        }
Beispiel #3
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();
        }
    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();
    }
Beispiel #6
0
        protected virtual void OnShellSectionPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (_isDisposed)
            {
                return;
            }

            if (e.PropertyName == ShellSection.CurrentItemProperty.PropertyName)
            {
                var newContent = ShellSection.CurrentItem;
                var oldContent = _currentContent;

                if (newContent == null)
                {
                    return;
                }

                if (_currentContent == null)
                {
                    _currentContent = newContent;
                    _currentIndex   = ShellSectionController.GetItems().IndexOf(_currentContent);
                    _tracker.Page   = ((IShellContentController)newContent).Page;
                    return;
                }

                var items = ShellSectionController.GetItems();
                if (items.Count == 0)
                {
                    return;
                }

                var oldIndex    = _currentIndex;
                var newIndex    = items.IndexOf(newContent);
                var oldRenderer = _renderers[oldContent];

                // this means the currently visible item has been removed
                if (oldIndex == -1 && _currentIndex <= newIndex)
                {
                    newIndex++;
                }

                _currentContent = newContent;
                _currentIndex   = newIndex;

                if (!_renderers.ContainsKey(newContent))
                {
                    return;
                }

                var currentRenderer = _renderers[newContent];
                _isAnimatingOut = oldRenderer;
                _pageAnimation?.StopAnimation(true);
                _pageAnimation = null;
                _pageAnimation = CreateContentAnimator(oldRenderer, currentRenderer, oldIndex, newIndex, _containerArea);

                if (_pageAnimation != null)
                {
                    _pageAnimation.AddCompletion((p) =>
                    {
                        if (_isDisposed)
                        {
                            return;
                        }

                        if (p == UIViewAnimatingPosition.End)
                        {
                            RemoveNonVisibleRenderers();
                        }
                    });

                    _pageAnimation.StartAnimation();
                }
                else
                {
                    RemoveNonVisibleRenderers();
                }
            }
        }
Beispiel #7
0
        void LayoutSidebar(bool animate)
        {
            if (_gestureActive)
            {
                return;
            }

            if (animate && _flyoutAnimation != null)
            {
                return;
            }

            if (!animate && _flyoutAnimation != null)
            {
                _flyoutAnimation.StopAnimation(true);
                _flyoutAnimation = null;
            }

            if (Forms.IsiOS10OrNewer)
            {
                if (IsOpen)
                {
                    UpdateTapoffView();
                }

                if (animate && TapoffView != null)
                {
                    var tapOffViewAnimation = CABasicAnimation.FromKeyPath(@"opacity");
                    tapOffViewAnimation.BeginTime = 0;
                    tapOffViewAnimation.Duration  = AnimationDurationInSeconds;
                    tapOffViewAnimation.SetFrom(NSNumber.FromFloat(TapoffView.Layer.Opacity));
                    tapOffViewAnimation.SetTo(NSNumber.FromFloat(IsOpen ? 1 : 0));
                    tapOffViewAnimation.FillMode            = CAFillMode.Forwards;
                    tapOffViewAnimation.RemovedOnCompletion = false;

                    _flyoutAnimation = new UIViewPropertyAnimator(AnimationDurationInSeconds, UIViewAnimationCurve.EaseOut, () =>
                    {
                        FlyoutTransition.LayoutViews(View.Bounds, IsOpen ? 1 : 0, Flyout.ViewController.View, Detail.View, _flyoutBehavior);

                        if (TapoffView != null)
                        {
                            TapoffView.Layer.AddAnimation(tapOffViewAnimation, "opacity");
                        }
                    });

                    _flyoutAnimation.AddCompletion((p) =>
                    {
                        if (p == UIViewAnimatingPosition.End)
                        {
                            if (TapoffView != null)
                            {
                                TapoffView.Layer.Opacity = IsOpen ? 1 : 0;
                                TapoffView.Layer.RemoveAllAnimations();
                            }

                            UpdateTapoffView();
                            _flyoutAnimation = null;
                        }
                    });

                    _flyoutAnimation.StartAnimation();
                    View.LayoutIfNeeded();
                }
                else if (_flyoutAnimation == null)
                {
                    FlyoutTransition.LayoutViews(View.Bounds, IsOpen ? 1 : 0, Flyout.ViewController.View, Detail.View, _flyoutBehavior);
                    UpdateTapoffView();

                    if (TapoffView != null)
                    {
                        TapoffView.Layer.Opacity = IsOpen ? 1 : 0;
                    }
                }
            }
            else
            {
                if (animate)
                {
                    UIView.BeginAnimations(FlyoutAnimationName);
                }

                FlyoutTransition.LayoutViews(View.Bounds, IsOpen ? 1 : 0, Flyout.ViewController.View, Detail.View, _flyoutBehavior);

                if (animate)
                {
                    UIView.SetAnimationCurve(AnimationCurve);
                    UIView.SetAnimationDuration(AnimationDurationInSeconds);
                    UIView.CommitAnimations();
                    View.LayoutIfNeeded();
                }
                UpdateTapoffView();
            }

            void UpdateTapoffView()
            {
                if (IsOpen && _flyoutBehavior == FlyoutBehavior.Flyout)
                {
                    AddTapoffView();
                }
                else
                {
                    RemoveTapoffView();
                }
            }
        }
Beispiel #8
0
 public static void SetCompletion(this UIViewPropertyAnimator animator)
 {
     animator.AddCompletion((a) => { });
 }
Beispiel #9
0
 /// <summary>
 /// Convenience function to set the completion with a parameter closure
 /// </summary>
 /// <param name="animator"></param>
 public static void SetCompletion(this UIViewPropertyAnimator animator, Action <UIViewAnimatingPosition> completion)
 {
     animator.AddCompletion(completion);
 }