Exemple #1
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;
        }
    }
        public override void StartInteractiveTransition(IUIViewControllerContextTransitioning transitionContext)
        {
            base.StartInteractiveTransition(transitionContext);

            Action animation = null;

            if (IsPresenting)
            {
                toView.Frame     = transitionContext.ContainerView.Bounds;
                toView.Transform = CGAffineTransform.MakeTranslation(0, toView.Frame.Size.Height);
                transitionContext.ContainerView.AddSubview(toView);
                animation = () => toView.Transform = CGAffineTransform.MakeIdentity();
            }
            else
            {
            }

            if (WantsInteractiveStart)
            {
                animator = new UIViewPropertyAnimator(DEFAULT_DURATION, UIViewAnimationCurve.Linear, animation);
            }
            else
            {
                animator = CreateDefaultAnimator();
                animator.AddCompletion(position => transitionContext.CompleteTransition(true));
                animator.AddAnimations(animation);
                animator.StartAnimation();
            }
        }
Exemple #3
0
        void IDisconnectable.Disconnect()
        {
            _pageAnimation?.StopAnimation(true);
            _pageAnimation = null;
            if (ShellSection != null)
            {
                ShellSection.PropertyChanged -= OnShellSectionPropertyChanged;
            }

            if (ShellSectionController != null)
            {
                ShellSectionController.ItemsCollectionChanged -= OnShellSectionItemsChanged;
            }

            if (_shellContext?.Shell != null)
            {
                _shellContext.Shell.PropertyChanged -= HandleShellPropertyChanged;
            }

            if (_renderers != null)
            {
                foreach (var renderer in _renderers)
                {
                    var oldRenderer = renderer.Value;
                    var element     = oldRenderer.Element;
                    element?.ClearValue(Platform.RendererProperty);
                    (renderer.Value as IDisconnectable)?.Disconnect();
                }
            }
        }
Exemple #4
0
        public async Task SendMessage()
        {
            var item = new ConversationItem
            {
                Input = this.txtInput.Text,
                Id    = this.Id
            };

            Action setOpacityNone = () =>
            {
                this.viewText.Alpha = 0;
            };

            Action <object> setOpacityFull = (o) =>
            {
                this.OpacityFull();
            };


            UIViewPropertyAnimator propertyAnimatorOpacityNone = new UIViewPropertyAnimator(2, UIViewAnimationCurve.EaseInOut, setOpacityNone);

            //propertyAnimatorOpacityNone.StartAnimation();

            var Response = await this.ViewModel.SendMessage(item);

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

            this.apiResponse   = Response;
            this.txtTitle.Text = this.apiResponse.Replace("[", "").Replace("]", "").Replace("\",\"", Environment.NewLine).Replace("\"", "");
            this.txtInput.Text = "";
        }
Exemple #5
0
        void HandlePanGesture(UIPanGestureRecognizer pan)
        {
            var    translation  = pan.TranslationInView(View).X;
            double openProgress = 0;
            double openLimit    = Flyout.ViewController.View.Frame.Width;

            if (IsOpen)
            {
                openProgress = 1 - (-translation / openLimit);
            }
            else
            {
                openProgress = translation / openLimit;
            }

            openProgress = Math.Min(Math.Max(openProgress, 0.0), 1.0);
            var openPixels = openLimit * openProgress;

            switch (pan.State)
            {
            case UIGestureRecognizerState.Changed:
                _gestureActive = true;

                if (TapoffView == null)
                {
                    AddTapoffView();
                }

                if (_flyoutAnimation != null)
                {
                    TapoffView.Layer.RemoveAllAnimations();
                    _flyoutAnimation?.StopAnimation(true);
                    _flyoutAnimation = null;
                }

                TapoffView.Layer.Opacity = (float)openProgress;

                FlyoutTransition.LayoutViews(View.Bounds, (nfloat)openProgress, Flyout.ViewController.View, Detail.View, _flyoutBehavior);
                break;

            case UIGestureRecognizerState.Ended:
                _gestureActive = false;
                if (IsOpen)
                {
                    if (openProgress < .8)
                    {
                        IsOpen = false;
                    }
                }
                else
                {
                    if (openProgress > 0.2)
                    {
                        IsOpen = true;
                    }
                }
                LayoutSidebar(true);
                break;
            }
        }
Exemple #6
0
 private void PerformFlyover(Flyover flyover)
 {
     if (!flyover.Coordinate.IsValid())
     {
         return;
     }
     if (_mapView == null)
     {
         return;
     }
     // Increase heading by heading step for _mapCamera
     _mapCamera.Heading += Configuration.HeadingStep;
     _mapCamera.Heading  = _mapCamera.Heading % 360;
     // Initialize UIViewPropertyAnimator
     _animator = new UIViewPropertyAnimator(
         Configuration.Duration,
         Curve,
         animations: () => {
         _mapView.Camera = _mapCamera;
     });
     // Add completion
     _animator?.SetCompletion((a) => {
         if (_flyover.NearlyEquals(flyover))
         {
             PerformFlyover(flyover);
         }
     });
     // Start animation
     _animator?.StartAnimation();
 }
        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 #8
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 #9
0
        private void OpacityFull()
        {
            this.txtTitle.Text = this.apiResponse;

            Action setOpacityFull = () =>
            {
                this.viewText.Alpha = 1;
            };

            UIViewPropertyAnimator propertyAnimatorOpacityFull = new UIViewPropertyAnimator(4, UIViewAnimationCurve.EaseInOut, setOpacityFull);

            propertyAnimatorOpacityFull.StartAnimation();
        }
Exemple #10
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 #11
0
        public CustomPanAnimation(UIView view)
        {
            superViewWidth = view.Superview.Frame.Width;
            xOffset        = superViewWidth - view.Frame.Width;

            var recognizer = new UIPanGestureRecognizer((UIPanGestureRecognizer obj) =>
            {
                switch (obj.State)
                {
                case UIGestureRecognizerState.Began:
                    animator = new UIViewPropertyAnimator(1, UIViewAnimationCurve.EaseOut, () =>
                    {
                        var velocity = obj.VelocityInView(view);
                        if (velocity.X < 0)
                        {
                            direction = -1;
                        }
                        else
                        {
                            direction = 1;
                        }

                        var frame = view.Frame;
                        frame.Offset(direction * xOffset, 0);
                        view.Frame = frame;
                    });
                    animator.PauseAnimation();
                    progressWhenInterrupted = animator.FractionComplete;
                    break;

                case UIGestureRecognizerState.Changed:
                    var translation           = obj.TranslationInView(view);
                    animator.FractionComplete = (direction * translation.X / xOffset) + progressWhenInterrupted;
                    break;

                case UIGestureRecognizerState.Ended:
                    if (Math.Abs(animator.FractionComplete) < 0.3)
                    {
                        animator.Reversed = true;
                    }
                    var timing = new UICubicTimingParameters(UIViewAnimationCurve.EaseOut);
                    animator.ContinueAnimation(timing, 0);
                    break;
                }
            });

            view.UserInteractionEnabled = true;
            view.AddGestureRecognizer(recognizer);
        }
Exemple #12
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();
    }
Exemple #13
0
 public void Start(Flyover flyover)
 {
     // Set flyover
     _flyover = flyover;
     if (UIApplication.SharedApplication.ApplicationState != UIApplicationState.Active)
     {
         // Return out of function
         return;
     }
     // Change state
     State = FlyoverCameraState.Started;
     // Stop current animation
     _animator?.ForceStopAnimation();
     // Set center coordinate
     _mapCamera.CenterCoordinate = flyover.Coordinate;
     // Check if duration is zero or the current mapView camera
     // equals nearly the same to the current flyover
     if (new Flyover(_mapView.Camera).NearlyEquals(_flyover))
     {
         // Simply perform flyover as we are still looking at the same coordinate
         PerformFlyover(flyover);
     }
     else if (Configuration.RegionChangeAnimation == RegionChangeAnimation.Animated &&
              Configuration.Duration > 0)
     {
         // Apply StartAnimationMode animated
         // Initialize start animator
         var startAnimator = new UIViewPropertyAnimator(
             duration: Configuration.Duration,
             curve: Curve,
             animations: () => {
             _mapView.Camera = _mapCamera;
         });
         // Add completion
         startAnimator.SetCompletion((x) => PerformFlyover(_flyover));
         // Start animation
         startAnimator.StartAnimation();
     }
     else
     {
         // No animation should be applied
         // Set MapView Camera to look at coordinate
         _mapView.Camera = _mapCamera;
         // Perform flyover
         PerformFlyover(_flyover);
     }
 }
Exemple #14
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 #15
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;
        }
    }
        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();
    }
Exemple #18
0
        public void Stop()
        {
            // Change state
            State = FlyoverCameraState.Stopped;
            // Unwrap MapView Camera Heading and fractionComplete
            if (_mapView == null ||
                _animator == null)
            {
                _animator?.ForceStopAnimation();
                _animator = null;
                return;
            }
            var heading          = _mapView.Camera.Heading;
            var fractionComplete = _animator.FractionComplete;

            // Force stop the animation
            _animator?.ForceStopAnimation();
            // Initialize Animator with stop animation
            _animator = new UIViewPropertyAnimator(
                duration: 0,
                curve: Curve,
                animations: () => {
                // Subtract the HeadingStep from current heading to retrieve start value
                heading -= Configuration.HeadingStep;
                // Initialize the percentage of the completed heading step
                var percentageCompletedHeadingStep = (double)fractionComplete * Configuration.HeadingStep;
                // Set MapCamera Heading
                _mapCamera.Heading = (heading + percentageCompletedHeadingStep) % 360;
                // Set MapView Camera
                _mapView.Camera = _mapCamera;
            });
            // Start animation
            _animator?.StartAnimation();
            // Clear animator as animation has been handled
            _animator = null;
        }
Exemple #19
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();
                }
            }
        }
    void Panned(object r)
    {
        var recognizer = r as UIPanGestureRecognizer;

        switch (recognizer.State)
        {
        case UIGestureRecognizerState.Began:
            StartAnimationIfNeeded();
            animator.PauseAnimation();
            animationProgress = animator.FractionComplete;
            break;

        case UIGestureRecognizerState.Changed:
            var fraction = -recognizer.TranslationInView(momentumView).Y / closedTransform.y0;
            if (isOpen)
            {
                fraction *= -1;
            }

            if (animator.Reversed)
            {
                fraction *= -1;
            }

            animator.FractionComplete = fraction + animationProgress;
            break;

        case UIGestureRecognizerState.Ended:
        case UIGestureRecognizerState.Cancelled:
            var yVelocity   = recognizer.VelocityInView(momentumView).Y;
            var shouldClose = yVelocity > 0;             // todo: should use projection instead

            if (yVelocity == 0)
            {
                animator.ContinueAnimation(parameters: null, durationFactor: 0);
                break;
            }
            if (isOpen)
            {
                if (!shouldClose && !animator.Reversed)
                {
                    animator.Reversed = !animator.Reversed;
                }
                if (shouldClose && animator.Reversed)
                {
                    animator.Reversed = !animator.Reversed;
                }
            }
            else
            {
                if (shouldClose && !animator.Reversed)
                {
                    animator.Reversed = !animator.Reversed;
                }
                if (!shouldClose && animator.Reversed)
                {
                    animator.Reversed = !animator.Reversed;
                }
            }
            var fractionRemaining = 1 - animator.FractionComplete;

            var distanceRemaining = fractionRemaining * closedTransform.y0;

            if (distanceRemaining == 0)
            {
                animator.ContinueAnimation(null, 0);
                break;
            }

            var relativeVelocity  = NMath.Min(NMath.Abs(yVelocity) / distanceRemaining, 30);
            var timingParameters  = UISpringTiming.MakeTimingParameters(damping: 0.8f, response: 0.3f, initialVelocity: new CGVector(dx: relativeVelocity, dy: relativeVelocity));
            var preferredDuration = new UIViewPropertyAnimator(duration: 0, parameters: timingParameters).Duration;
            var durationFactor    = preferredDuration / animator.Duration;
            animator.ContinueAnimation(parameters: timingParameters, durationFactor: (nfloat)durationFactor);
            break;

        default:
            break;
        }
    }
Exemple #21
0
 public static void ForceStopAnimation(this UIViewPropertyAnimator animator)
 {
     // Stop animation without finishing.
     animator.StopAnimation(true);
 }
Exemple #22
0
 public static void SetCompletion(this UIViewPropertyAnimator animator)
 {
     animator.AddCompletion((a) => { });
 }
Exemple #23
0
        public CustomSlideAnimation(UIView view, Axis axis)
        {
            superViewWidth  = view.Superview.Frame.Width;
            superViewHeight = view.Superview.Frame.Height;

            xOffset = superViewWidth - view.Frame.Width;
            yOffset = superViewHeight - view.Frame.Height - 40;

            var recognizer = new UIPanGestureRecognizer((UIPanGestureRecognizer obj) =>
            {
                switch (obj.State)
                {
                case UIGestureRecognizerState.Began:
                    animator = new UIViewPropertyAnimator(1, UIViewAnimationCurve.EaseOut, () =>
                    {
                        var velocity = obj.VelocityInView(view);
                        if (axis == Axis.X && velocity.X < 0)
                        {
                            direction = -1;
                        }
                        else if (axis == Axis.Y && velocity.Y < 0)
                        {
                            direction = -1;
                        }
                        else
                        {
                            direction = 1;
                        }

                        var frame = view.Frame;
                        if (axis == Axis.Y)
                        {
                            frame.Offset(0, direction * yOffset);
                        }
                        else
                        {
                            frame.Offset(direction * xOffset, 0);
                        }
                        view.Frame = frame;
                    });
                    animator.PauseAnimation();
                    progressWhenInterrupted = animator.FractionComplete;
                    break;

                case UIGestureRecognizerState.Changed:
                    var translation = obj.TranslationInView(view);
                    if (axis == Axis.Y)
                    {
                        animator.FractionComplete = (direction * translation.Y / yOffset) + progressWhenInterrupted;
                    }
                    else
                    {
                        animator.FractionComplete = (direction * translation.X / xOffset) + progressWhenInterrupted;
                    }
                    break;

                case UIGestureRecognizerState.Ended:
                    animator.PauseAnimation();
                    break;
                }
            });

            view.UserInteractionEnabled = true;
            view.AddGestureRecognizer(recognizer);
        }
Exemple #24
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;
             *  }
             * );*/
        }
        public async Task HandleTouch(TouchStatus status, TouchInteractionStatus?interactionStatus = null)
        {
            if (IsCanceled || effect == null)
            {
                return;
            }

            if (effect?.IsDisabled ?? true)
            {
                return;
            }

            var canExecuteAction = effect.CanExecute;

            if (interactionStatus == TouchInteractionStatus.Started)
            {
                effect?.HandleUserInteraction(TouchInteractionStatus.Started);
                interactionStatus = null;
            }

            effect?.HandleTouch(status);
            if (interactionStatus.HasValue)
            {
                effect?.HandleUserInteraction(interactionStatus.Value);
            }

            if (effect == null || (!effect.NativeAnimation && !IsButton) || (!canExecuteAction && status == TouchStatus.Started))
            {
                return;
            }

            var control = effect.Element;

            if (control?.GetRenderer() is not UIView renderer)
            {
                return;
            }

            var color        = effect.NativeAnimationColor;
            var radius       = effect.NativeAnimationRadius;
            var shadowRadius = effect.NativeAnimationShadowRadius;
            var isStarted    = status == TouchStatus.Started;

            defaultRadius       = (float?)(defaultRadius ?? renderer.Layer.CornerRadius);
            defaultShadowRadius = (float?)(defaultShadowRadius ?? renderer.Layer.ShadowRadius);
            defaultShadowOpacity ??= renderer.Layer.ShadowOpacity;

            var tcs = new TaskCompletionSource <UIViewAnimatingPosition>();

            UIViewPropertyAnimator.CreateRunningPropertyAnimator(.2, 0, UIViewAnimationOptions.AllowUserInteraction,
                                                                 () =>
            {
                if (color == Color.Default)
                {
                    renderer.Layer.Opacity = isStarted ? 0.5f : (float)control.Opacity;
                }
                else
                {
                    renderer.Layer.BackgroundColor = (isStarted ? color : control.BackgroundColor).ToCGColor();
                }

                renderer.Layer.CornerRadius = isStarted ? radius : defaultRadius.GetValueOrDefault();

                if (shadowRadius >= 0)
                {
                    renderer.Layer.ShadowRadius  = isStarted ? shadowRadius : defaultShadowRadius.GetValueOrDefault();
                    renderer.Layer.ShadowOpacity = isStarted ? 0.7f : defaultShadowOpacity.GetValueOrDefault();
                }
            }, endPos => tcs.SetResult(endPos));
            await tcs.Task;
        }
Exemple #26
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();
                }
            }
        }
Exemple #27
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);
 }