Ejemplo n.º 1
0
        private UIPanGestureRecognizer CreatePanGesture()
        {
            UIPanGestureRecognizer result = null;
            nfloat dy   = 0;
            nfloat navX = 70;

            result = new UIPanGestureRecognizer(() => {
                if ((result.State == UIGestureRecognizerState.Began || result.State == UIGestureRecognizerState.Changed) && (result.NumberOfTouches == 1))
                {
                    _isDragging = true;

                    var p0       = result.LocationInView(this);
                    var currentY = (_position == ChartPosition.Top) ? topY : downY;

                    if (dy.CompareTo(0) == 0)
                    {
                        dy = p0.Y - currentY;
                    }

                    var p1 = new CGPoint(_containerView.Center.X, p0.Y - dy);
                    if (p1.Y > topY || p1.Y < downY)
                    {
                        return;
                    }
                    _containerView.Center = p1;
                }
                else if (result.State == UIGestureRecognizerState.Ended)
                {
                    nfloat newY;
                    ChartPosition newPosition;

                    if (_position == ChartPosition.Top && _containerView.Center.Y <= topY - navX)
                    {
                        newPosition = ChartPosition.Down;
                        newY        = downY;
                    }
                    else if (_position == ChartPosition.Down && _containerView.Center.Y >= downY + navX)
                    {
                        newPosition = ChartPosition.Top;
                        newY        = topY;
                    }
                    else
                    {
                        newPosition = _position;
                        newY        = (_position == ChartPosition.Top) ? topY : downY;
                    }

                    UIView.Animate(0.3, 0, UIViewAnimationOptions.CurveEaseOut,
                                   () => {
                        _containerView.Center = new CGPoint(_containerView.Center.X, newY);
                    }, () => {
                        _isDragging = false;
                        _position   = newPosition;
                    });
                    dy = 0;
                }
            });

            return(result);
        }