Пример #1
0
        private void PanGesture(UIPanGestureRecognizer recognizer)
        {
            var translation = recognizer.TranslationInView(View);
            var y           = View.Frame.GetMinY();

            View.Frame = new CGRect(0, y + translation.Y, View.Frame.Width, View.Frame.Height);
            recognizer.SetTranslation(CGPoint.Empty, View);

            var velocity = recognizer.VelocityInView(View);

            if ((y + translation.Y >= fullView) & (y + translation.Y <= partialView))
            {
                View.Frame = new CGRect(0, y + translation.Y, View.Frame.Width, View.Frame.Height);
                recognizer.SetTranslation(CGPoint.Empty, View);
            }

            if (recognizer.State == UIGestureRecognizerState.Ended)
            {
                var duration = velocity.Y < 0 ? ((y - fullView) / -velocity.Y) : ((partialView - y) / velocity.Y);
                duration = duration > 1.3 ? 1 : duration;

                UIView.Animate(duration, 0.0, UIViewAnimationOptions.AllowUserInteraction, () =>
                {
                    if (velocity.Y >= 0)
                    {
                        View.Frame = new CGRect(0, partialView, View.Frame.Width, View.Frame.Height);
                    }
                    else
                    {
                        View.Frame = new CGRect(0, fullView, View.Frame.Width, View.Frame.Height);
                    }
                }, null);
            }
        }
Пример #2
0
        private void panGestureRecognizerHandlerChanged(UIPanGestureRecognizer gesture)
        {
            CGPoint translation = gesture.TranslationInView(ContentView);

            ContentView_LayoutCenterY.Constant += translation.Y;
            gesture.SetTranslation(new CGPoint(0.0, 0.0), ContentView);
        }
        private void HandlePanFrom(UIPanGestureRecognizer recognizer)
        {
            if (recognizer.State == UIGestureRecognizerState.Began)
            {
                PointF touchLocation = recognizer.LocationInView(recognizer.View);
                touchLocation = this.ConvertPointFromView(touchLocation);
                this.SelectNodeForTouch(touchLocation);
            }
            else if (recognizer.State == UIGestureRecognizerState.Changed)
            {
                PointF translation = recognizer.TranslationInView(recognizer.View);
                translation = new PointF(translation.X, -translation.Y);
                this.PanForTranslation(translation);
                recognizer.SetTranslation(new PointF(0, 0), recognizer.View);
            }
            else if (recognizer.State == UIGestureRecognizerState.Ended)
            {
                float scrollDuration = 0.2f;

                if (this.SelectedNode.Name != ANIMAL_NODE_NAME)
                {
                    PointF velocity = recognizer.VelocityInView(recognizer.View);
                    PointF p        = mult(velocity, scrollDuration);

                    PointF position = this.SelectedNode.Position;
                    PointF newPos   = new PointF(position.X + p.X, position.Y + p.Y);
                    newPos = this.BoundLayerPosition(newPos);
                    this.SelectedNode.RemoveAllActions();

                    SKAction moveTo = SKAction.MoveTo(newPos, scrollDuration);
                    moveTo.TimingMode = SKActionTimingMode.EaseOut;
                    this.SelectedNode.RunAction(moveTo);
                }
            }
        }
Пример #4
0
        partial void DidPan(UIPanGestureRecognizer gesture)
        {
            if (this.virtualObject != null)
            {
                switch (gesture.State)
                {
                case UIGestureRecognizerState.Changed:
                    var translation = gesture.TranslationInView(this.sceneView);

                    var previousPosition = this.lastPanTouchPosition ?? CGPointExtensions.Create(this.sceneView.ProjectPoint(this.virtualObject.Position));
                    // Calculate the new touch position
                    var currentPosition = new CGPoint(previousPosition.X + translation.X, previousPosition.Y + translation.Y);
                    using (var hitTestResult = this.sceneView.SmartHitTest(currentPosition))
                    {
                        if (hitTestResult != null)
                        {
                            this.virtualObject.Position = hitTestResult.WorldTransform.GetTranslation();
                            // Refresh the probe as the object keeps moving
                            this.requiresProbeRefresh = true;
                        }
                    }

                    this.lastPanTouchPosition = currentPosition;
                    // reset the gesture's translation
                    gesture.SetTranslation(CGPoint.Empty, this.sceneView);
                    break;

                default:
                    // Clear the current position tracking.
                    this.lastPanTouchPosition = null;
                    break;
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Adjusts the size of the view when the user pans (if <see cref="AllowsManualResize"/> is <value>true</value>).
        /// </summary>
        /// <param name="recognizer">Gesture recognizer that is handling user interaction.</param>
        private void HandleMoveView(UIPanGestureRecognizer recognizer)
        {
            // Do nothing if user resize isn't enabled
            if (!AllowsManualResize)
            {
                return;
            }

            // Get the distance moved
            var translation = recognizer.TranslationInView(View);

            // In compact width scrolling up (negative translation) increases height as the card moves up
            if (TraitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Regular)
            {
                // translate height constraint
                _heightConstraint.Constant += translation.Y;
            }
            else
            {
                // translate height constraint
                _heightConstraint.Constant -= translation.Y;
            }

            // Prevent making the view too large
            if (_heightConstraint.Constant > MaxHeightConstraint)
            {
                _heightConstraint.Constant = MaxHeightConstraint;
            }

            // Prevent making the view too small
            if (_heightConstraint.Constant < MinimumHeight)
            {
                _heightConstraint.Constant = MinimumHeight;
            }

            // Enables 'flick' gesture to switch between states
            if (recognizer.State == UIGestureRecognizerState.Ended)
            {
                if (Math.Abs(recognizer.VelocityInView(View).Y) > 0)
                {
                    HandleFlick(recognizer);
                }

                if (_heightConstraint.Constant == MinimumHeight && AllowsMinimizedState)
                {
                    _currentState = BottomSheetState.Minimized;
                }
                else if (_heightConstraint.Constant == MaxHeightConstraint)
                {
                    _currentState = BottomSheetState.Full;
                }
                else
                {
                    _currentState = BottomSheetState.Partial;
                }
            }

            recognizer.SetTranslation(new CoreGraphics.CGPoint(0, 0), View);
        }
        void OnMenuPan(UIPanGestureRecognizer panGestureRecognizer)
        {
            var translationX = panGestureRecognizer.TranslationInView(View).X;
            var menuView     = menuViewController.View;

            switch (panGestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
            {
                menuAnimator?.StopAnimation(true);
            }
            break;

            case UIGestureRecognizerState.Changed:
            {
                var potentialNewX     = menuView.Frame.X + translationX;
                var translationFactor = GetMenuTranslationFactor(potentialNewX);
                var newX             = menuView.Frame.X + (translationX * translationFactor);
                var totalXDistance   = UIScreen.MainScreen.Bounds.Width - Constants.MenuRightMargin;
                var percentMaximized = (newX + UIScreen.MainScreen.Bounds.Width) / totalXDistance;

                menuView.Frame = new CGRect
                {
                    Location = new CGPoint
                    {
                        X = newX,
                        Y = menuView.Frame.Y,
                    },
                    Size = menuView.Frame.Size,
                };

                menuViewController.SetPercentMaximized((float)percentMaximized);
                menuBackgroundView.Alpha = percentMaximized;
                panGestureRecognizer.SetTranslation(CGPoint.Empty, View);
            }
            break;

            case UIGestureRecognizerState.Ended:
            {
                var x                        = menuView.Frame.X;
                var velocityX                = panGestureRecognizer.VelocityInView(View).X;
                var totalXDistance           = UIScreen.MainScreen.Bounds.Width - Constants.MenuRightMargin;
                var shouldMaximizeByLocation = (x + UIScreen.MainScreen.Bounds.Width) >= totalXDistance / 3f;

                var shouldMaximizeByVelocity = velocityX > Constants.PulloutVelocityThreshold;
                var shouldMinimizeByVelocity = -velocityX > Constants.PulloutVelocityThreshold;
                var shouldMaximize           = !shouldMinimizeByVelocity && (shouldMaximizeByLocation || shouldMaximizeByVelocity);

                var DEST_X            = shouldMaximize ? -Constants.MenuRightMargin : -UIScreen.MainScreen.Bounds.Width;
                var remainingDistance = Math.Abs(x - DEST_X);

                var initialVelocity = MenuIsExceedingBoundaries(menuView.Frame) ? 0f : (nfloat)Math.Abs(velocityX / remainingDistance);
                AnimateMenu(shouldMaximize ? MenuState.Open : MenuState.Closed, (float)initialVelocity);
            }
            break;
            }
        }
        private void InfoPanGesture(UIPanGestureRecognizer recognizer)
        {
            if (_height < 0)
            {
                _height = _infoBlockView.Bounds.Height + IPHONE_X_OFFSET;
            }

            _maxInfoBlockTop = base.View.Bounds.Height - _height;

            var translation = recognizer.TranslationInView(_infoBlockView);
            var velocity    = recognizer.VelocityInView(_infoBlockView);

            if (Math.Abs(velocity.X) > Math.Abs(velocity.Y))
            {
                return;
            }

            var y = _infoBlockView.Frame.GetMinY();

            if (recognizer.State == UIGestureRecognizerState.Changed)
            {
                if ((y + translation.Y >= _maxInfoBlockTop) && (y + translation.Y <= _minInfoBlockTop))
                {
                    _infoBlockView.Frame = new CGRect(0, y + translation.Y, _infoBlockView.Bounds.Width, _height);
                }
                else
                {
                    _infoBlockView.Frame = new CGRect(0, (translation.Y >= 0) ? _minInfoBlockTop : _maxInfoBlockTop,
                                                      _infoBlockView.Bounds.Width, _height);
                    _titleLabel.Alpha    = (translation.Y >= 0) ? 0 : 1;
                    _addressLabel.Alpha  = (translation.Y >= 0) ? 0 : 1;
                    _distanceView.Alpha  = (translation.Y >= 0) ? 0 : 1;
                    _workTimeLabel.Alpha = (translation.Y >= 0) ? 0 : 1;
                    _infoLabel.Alpha     = (translation.Y >= 0) ? 0 : 1;
                }

                recognizer.SetTranslation(CGPoint.Empty, _infoBlockView);
            }
            else if (recognizer.State == UIGestureRecognizerState.Ended)
            {
                var duration = velocity.Y < 0 ? (y - _maxInfoBlockTop) / -velocity.Y : (_minInfoBlockTop - y) / velocity.Y;
                duration = duration > 1 ? (nfloat)0.8 : duration;

                UIView.Animate(duration, 0, UIViewAnimationOptions.AllowUserInteraction, () =>
                {
                    _infoBlockView.Frame = new CGRect(0, (velocity.Y >= 0) ? _minInfoBlockTop : _maxInfoBlockTop,
                                                      _infoBlockView.Bounds.Width, _height);

                    _titleLabel.Alpha    = (velocity.Y >= 0) ? 0 : 1;
                    _addressLabel.Alpha  = (velocity.Y >= 0) ? 0 : 1;
                    _distanceView.Alpha  = (velocity.Y >= 0) ? 0 : 1;
                    _workTimeLabel.Alpha = (velocity.Y >= 0) ? 0 : 1;
                    _infoLabel.Alpha     = (velocity.Y >= 0) ? 0 : 1;
                }, null);
            }
        }
Пример #8
0
        public void Null()
        {
            using (var pgr = new UIPanGestureRecognizer(Null)) {
                pgr.SetTranslation(CGPoint.Empty, null);

                var pt = pgr.TranslationInView(null);
                Assert.That(pt, Is.EqualTo(CGPoint.Empty), "TranslationInView");

                pt = pgr.VelocityInView(null);
                Assert.That(pt, Is.EqualTo(CGPoint.Empty), "VelocityInView");
            }
        }
Пример #9
0
        public void ResetMenu()
        {
            UIView piece      = panGesture.View;
            var    yComponent = piece.Superview.Frame.Height - 40f;

            ComponentExpanded = false;

            piece.Frame = new RectangleF(new PointF(piece.Frame.X, yComponent), piece.Frame.Size);

            panGesture.SetTranslation(new PointF(0, 0), piece.Superview);

            this.Draw(this.Frame);
        }
Пример #10
0
        void HandlePan(UIPanGestureRecognizer gesture)
        {
            if (gesture.State == UIGestureRecognizerState.Began)
            {
                gesture.SetTranslation(translate, this.View);
            }

            var pos = gesture.TranslationInView(this.View);

            translate = pos;

            UpdateTransform();
        }
        // Shift the image's center by the pan amount
        void PanImage(UIPanGestureRecognizer gestureRecognizer)
        {
            AdjustAnchorPointForGestureRecognizer(gestureRecognizer);
            var image = gestureRecognizer.View;

            if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed)
            {
                var translation = gestureRecognizer.TranslationInView(View);
                image.Center = new CGPoint(image.Center.X + translation.X, image.Center.Y + translation.Y);
                // Reset the gesture recognizer's translation to {0, 0} - the next callback will get a delta from the current position.
                gestureRecognizer.SetTranslation(CGPoint.Empty, image);
            }
        }
        void HandlePan(UIPanGestureRecognizer gesture)
        {
            if (gesture.State == UIGestureRecognizerState.Began)
            {
                gesture.SetTranslation(translate, this.View);
            }

            // Read the translation value from the gesture recognizer
            var pos = gesture.TranslationInView(this.View);

            // and save it to our class level translate property
            translate = pos;

            // and call UpdateTransform ()
            UpdateTransform();
        }
Пример #13
0
        private void Panned(UIPanGestureRecognizer gestureRecognizer)
        {
            if (this.items.Count < 2 || this.contentWidth <= this.View.Bounds.Width)
            {
                return;
            }

            var panLocation = gestureRecognizer.TranslationInView(this.ContentView);

            var offset = this.currentScrolledOffset - panLocation.X;

            // this is the total amount that we've scrolled away from zero
            this.LayoutContent(this.LimitOffset(offset));

            if (gestureRecognizer.State != UIGestureRecognizerState.Ended)
            {
                return;
            }

            var velocity = gestureRecognizer.VelocityInView(this.View).X;

            if (Math.Abs(velocity) < 500)
            {
                this.currentScrolledOffset = this.CalculatePannedLocation(offset, panLocation.X);
                this.ScrollContent(currentScrolledOffset);
            }
            else
            {
                if (panLocation.X < 0)
                {
                    var proposedOffset = this.GetNextOffset(offset);

                    this.currentScrolledOffset = proposedOffset;
                }
                else
                {
                    var proposedOffset = this.GetPriorOffset(offset);

                    this.currentScrolledOffset = proposedOffset;
                }

                this.ScrollContent(this.currentScrolledOffset);
            }

            gestureRecognizer.SetTranslation(PointF.Empty, this.View);
        }
        /// <summary>
        /// Method that gets invoked when drag gesture is performed.
        /// </summary>
        /// <param name="dragGesture">Drag gesture.</param>
        public void DragBottomSheet(UIPanGestureRecognizer dragGesture)
        {
            var translation  = dragGesture.TranslationInView(View);
            var velocity     = dragGesture.VelocityInView(View);
            var bottomSheetY = View.Frame.GetMinY();


            if (bottomSheetY + translation.Y <= m_PartialView && bottomSheetY + translation.Y >= m_FullView)
            {
                View.Frame = new CGRect(0, bottomSheetY + translation.Y, View.Frame.Width, View.Frame.Height);
                dragGesture.SetTranslation(m_CGPointZero, View);
            }

            if (dragGesture.State == UIGestureRecognizerState.Ended)
            {
                MoveSheetToBound(velocity.Y);
            }
        }
Пример #15
0
        private void panGestureRecognizerHandlerEnd(UIPanGestureRecognizer gesture)
        {
            if (ContentView_LayoutCenterY.Constant >= 50.0)
            {
                this.ViewModel.Update.Execute(null);
            }

            if (ContentView_LayoutCenterY.Constant <= -150.0)
            {
                this.showTableView(true);
            }
            else
            {
                this.showTableView(false);
            }

            gesture.SetTranslation(new CGPoint(0.0, 0.0), ContentView);
        }
Пример #16
0
        private void PanHandler(UIPanGestureRecognizer gesture)
        {
            CGPoint translation = gesture.TranslationInView(rotationView);

            if (gesture.State == UIGestureRecognizerState.Began)
            {
                tile.Frame = tile.Layer.PresentationLayer.Frame;
                tile.Layer.RemoveAllAnimations();
            }
            else if (gesture.State == UIGestureRecognizerState.Changed)
            {
                Stopwatch sw = Stopwatch.StartNew();

                var offsetX = translation.X;
                var offsetY = translation.Y;

                var newLeft = tile.Frame.GetMinX() + offsetX;
                var newTop  = tile.Frame.GetMinY() + offsetY;

                tile.Frame = new CGRect(newLeft, newTop, tile.Frame.Width, tile.Frame.Height);
                gesture.SetTranslation(new CGPoint(0, 0), View);
                sw.Stop();
                Console.WriteLine("Panning: " + sw.ElapsedMilliseconds);
            }
            else if (gesture.State == UIGestureRecognizerState.Ended)
            {
                Stopwatch sw = Stopwatch.StartNew();

                var inertia = gesture.VelocityInView(rotationView);
                var offsetX = inertia.X * animationOffsetRatio;
                var offsetY = inertia.Y * animationOffsetRatio;
                var newLeft = tile.Frame.X + offsetX;
                var newTop  = tile.Frame.Y + offsetY;

                UIView.Animate(animationDuration, 0, UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.AllowUserInteraction,
                               () => { tile.Frame = new CGRect(newLeft, newTop, tile.Frame.Width, tile.Frame.Height); },
                               () =>
                {
                    sw.Stop();
                    Console.WriteLine("Paned: " + sw.ElapsedMilliseconds);
                });
            }
        }
Пример #17
0
        void PanGestureMoveAround(UIPanGestureRecognizer gesture)
        {
            UIView piece = gesture.View;

            AdjustAnchorPointForGestureRecognizer(gesture);

            if (gesture.State == UIGestureRecognizerState.Began || gesture.State == UIGestureRecognizerState.Changed)
            {
                PointF translation = gesture.TranslationInView(piece.Superview);

                piece.Center = new PointF(piece.Center.X, piece.Center.Y + translation.Y);

                gesture.SetTranslation(new PointF(0, 0), piece.Superview);
            }
            else if (gesture.State == UIGestureRecognizerState.Ended)
            {
                SlideAndFix(gesture);
            }
        }
Пример #18
0
        private void HandlePan(UIPanGestureRecognizer recognizer)
        {
            if (recognizer.State != UIGestureRecognizerState.Began &&
                recognizer.State != UIGestureRecognizerState.Changed)
            {
                return;
            }

            var translation = recognizer.TranslationInView(Superview);

            _posX += translation.X;
            _posY += translation.Y;

            var maxX = (Bounds.Size.Width / 2) * _currentScale;
            var maxY = (Bounds.Size.Height / 2) * _currentScale;

            var minX = -(maxX - Bounds.Size.Width);
            var minY = -(maxY - Bounds.Size.Height);

            if (_posX > maxX)
            {
                _posX = maxX;
            }
            else if (_posX < minX)
            {
                _posX = minX;
            }
            if (_posY > maxY)
            {
                _posY = maxY;
            }
            else if (_posY < minY)
            {
                _posY = minY;
            }

            var translatedCenter = new CGPoint(_posX, _posY);

            Center = translatedCenter;

            recognizer.SetTranslation(CGPoint.Empty, this);
        }
Пример #19
0
        void panToShowView(UIPanGestureRecognizer p)
        {
            PointF translatedPoint = p.TranslationInView(View);

            if (p.State == UIGestureRecognizerState.Changed)
            {
                ShowingRightBar = (p.View.Frame.X > (Constants.ScreenFrame.Width - Constants.RightViewX / 2)) ? false : true;
                Console.WriteLine((Constants.ScreenFrame.Width - Constants.RightViewX / 2) + "   " + (p.View.Frame.X) + "   " + ShowingRightBar);

                if (p.View.Frame.X >= Constants.ScreenFrame.Width - Constants.RightViewX - 24)
                {
                    p.View.Center = new PointF(p.View.Center.X + translatedPoint.X, p.View.Center.Y);
                }
                p.SetTranslation(new PointF(), View);
            }
            if (p.State == UIGestureRecognizerState.Ended)
            {
                ShowingRightBar = (p.View.Frame.X > (Constants.ScreenFrame.Width - Constants.RightViewX / 2)) ? false : true;

                animateRightView(0.15f);
            }
        }
Пример #20
0
        void moveLine(UIPanGestureRecognizer gr)
        {
            // if no line selected, do nothing
            if (selectedLine == null)
            {
                return;
            }

            // When the pan gesture recognizer changes its position...
            if (gr.State == UIGestureRecognizerState.Changed)
            {
                // How far has the pan moved?
                CGPoint translation = gr.TranslationInView(this);

                // Add the translation to the current begin and end points of the line
                CGPoint begin = selectedLine.begin;
                CGPoint end   = selectedLine.end;
                begin.X += translation.X;
                begin.Y += translation.Y;
                end.X   += translation.X;
                end.Y   += translation.Y;

                // Set the new beginning and end points of the line
                selectedLine.begin = begin;
                selectedLine.end   = end;

                LineStore.updateCompletedLine(selectedLine);

                this.SetNeedsDisplay();

                gr.SetTranslation(new CGPoint(0, 0), this);
            }
            else if (gr.State == UIGestureRecognizerState.Ended)
            {
                selectedLine = null;
            }
        }
        void DismissFullPhotoMode(CGRect cellFrame, UIPanGestureRecognizer panGesture)
        {
            UIView.Animate(0.2, () => { panGesture.View.BackgroundColor = null; });

            var translation = panGesture.TranslationInView(panGesture.View);

            panGesture.View.Center = new CGPoint
            {
                X = panGesture.View.Center.X + translation.X,
                Y = panGesture.View.Center.Y + translation.Y
            };

            if (panGesture.State == UIGestureRecognizerState.Ended)
            {
                TabBarController.TabBar.Hidden = false;

                UIView.Animate(.3, () =>
                {
                    panGesture.View.Frame = cellFrame;
                }, panGesture.View.RemoveFromSuperview);
            }

            panGesture.SetTranslation(new CGPoint(0, 0), panGesture.View);
        }
Пример #22
0
        private void Panning(UIPanGestureRecognizer panGesture)
        {
            var translatedPoint = panGesture.TranslationInView(Superview);
            var gestureState    = panGesture.State;
            var yDelta          = panGesture.View.Center.Y + translatedPoint.Y;

            if (yDelta < _initialCenter.Y)
            {
                gestureState = UIGestureRecognizerState.Ended;
            }
            if (yDelta >= _finalCenter.Y)
            {
                gestureState = UIGestureRecognizerState.Ended;
            }

            if (gestureState == UIGestureRecognizerState.Began ||
                gestureState == UIGestureRecognizerState.Changed)
            {
                var progress         = (panGesture.View.Center.Y - _initialCenter.Y) / _rangeTotal;
                var invertedProgress = 1 - progress;
                var newWidth         = _finalSize.Width + _widthRage * invertedProgress;

                var tempFrame = panGesture.View.Frame;
                tempFrame.Size        = new CGSize(newWidth, newWidth * AspectRatio);
                panGesture.View.Frame = tempFrame;

                var finalX = _initialCenter.X + _centerXRange * progress;

                panGesture.View.Center = new CGPoint(finalX, panGesture.View.Center.Y + translatedPoint.Y);
                panGesture.SetTranslation(CGPoint.Empty, Superview);

                // Shrinking state
                var evt = OnShrinking;
                evt?.Invoke();
            }
            else if (gestureState == UIGestureRecognizerState.Ended)
            {
                var topDistance    = yDelta - _initialCenter.Y;
                var bottomDistance = _finalCenter.Y - yDelta;
                var chosenCenter   = CGPoint.Empty;
                var chosenSize     = CGSize.Empty;

                UserInteractionEnabled = false;

                if (topDistance > bottomDistance)
                {
                    // Set for bottom of screen animation
                    chosenCenter = _finalCenter;
                    chosenSize   = _finalSize;
                }
                else
                {
                    // Set for top of screen Animation
                    chosenCenter = _initialCenter;
                    chosenSize   = _initialSize;
                }

                if (panGesture.View.Center != chosenCenter)
                {
                    Animate(0.4, () =>
                    {
                        var tempFrame          = panGesture.View.Frame;
                        tempFrame.Size         = chosenSize;
                        panGesture.View.Frame  = tempFrame;
                        panGesture.View.Center = chosenCenter;
                    }, () =>
                    {
                        UserInteractionEnabled = true;
                    });
                }
                else
                {
                    UserInteractionEnabled = true;
                }
            }

            if (Shrunk)
            {
                var evt = OnShrunk;
                evt?.Invoke();
            }
            else
            {
                var evt = OnInitialSize;
                evt?.Invoke();
            }
        }
        void HandlePulloutPan(UIPanGestureRecognizer panGestureRecognizer)
        {
            var translationY = panGestureRecognizer.TranslationInView(View).Y;

            switch (panGestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
            {
                pulloutAnimator?.StopAnimation(true);
                mainPulloutView.PulloutBeganDragging(pulloutState);
            }
            break;

            case UIGestureRecognizerState.Changed:
            {
                var potentialNewY     = mainPulloutView.Frame.Y + translationY;
                var translationFactor = GetTranslationFactor(potentialNewY);
                var newY             = mainPulloutView.Frame.Y + (translationY * translationFactor);
                var totalYDistance   = (UIScreen.MainScreen.Bounds.Height - Constants.PulloutBottomMargin) - Constants.PulloutTopMargin;
                var percentMaximized = 1 - ((newY - Constants.PulloutTopMargin) / totalYDistance);

                mainPulloutView.Frame = new CGRect
                {
                    Location = new CGPoint
                    {
                        X = mainPulloutView.Frame.X,
                        Y = newY,
                    },
                    Size = mainPulloutView.Frame.Size,
                };

                mainPulloutView.SetPercentMaximized(percentMaximized);
                pulloutBackgroundView.Alpha = percentMaximized;


                var minimizedTotalDistance = pulloutMinDestY - pulloutNeutralDestY;
                var minimizedDeltaProgress = newY - pulloutNeutralDestY;
                minimizedDeltaProgress = minimizedDeltaProgress < 0 ? 0 : minimizedDeltaProgress;
                var percentMinimized = minimizedDeltaProgress / minimizedTotalDistance;
                percentMinimized = percentMinimized > 1 ? 1 : (percentMinimized < 0 ? 0 : percentMinimized);
                mainPulloutView.SetPercentMinimized(percentMinimized);

                panGestureRecognizer.SetTranslation(CGPoint.Empty, View);
            }
            break;

            case UIGestureRecognizerState.Ended:
            {
                var y         = mainPulloutView.Frame.Y;
                var velocityY = panGestureRecognizer.VelocityInView(View).Y;
                var shouldMaximizeByLocation = y <= pulloutMaxDestY || Math.Abs(y - pulloutMaxDestY) < (pulloutNeutralDestY - pulloutMaxDestY) / 2;
                var shouldMaximizeByVelocity = -velocityY > Constants.PulloutVelocityThreshold;
                var shouldMinimizeByVelocity = velocityY > Constants.PulloutVelocityThreshold;
                var shouldMaximize           = !shouldMinimizeByVelocity && (shouldMaximizeByLocation || shouldMaximizeByVelocity);
                var newPulloutState          = shouldMaximize ? PulloutState.Maximized : (isPulloutInMinMode ? PulloutState.Minimized : PulloutState.Neutral);
                var DEST_Y            = PulloutDestinationYFromState(newPulloutState);
                var remainingDistance = Math.Abs(y - DEST_Y);

                AnimatePullout(newPulloutState, (float)(PulloutIsExceedingBoundaries(mainPulloutView.Frame) ? 0f : (nfloat)Math.Abs(velocityY / remainingDistance)));
            }
            break;
            }
        }
        private void Panned(UIPanGestureRecognizer gestureRecognizer)
        {
            if (this.items.Count < 2 || this.contentWidth <= this.View.Bounds.Width)
            {
                return;
            }

            // quick hack for nested panoramas
            if (this.presentedController is UIPanoramaViewController)
            {
                return;
            }

            var panLocation = gestureRecognizer.TranslationInView(this.ContentView);

            var offset = this.currentScrolledOffset - panLocation.X;

            // this is the total amount that we've scrolled away from zero
            this.LayoutContent(this.LimitOffset(offset));

            if (gestureRecognizer.State != UIGestureRecognizerState.Ended)
            {
                return;
            }

            var velocity = gestureRecognizer.VelocityInView(this.View).X;

            if (Math.Abs(velocity) < 700)
            {
                this.currentScrolledOffset = this.CalculatePannedLocation(offset, panLocation.X);
                this.ScrollContent(currentScrolledOffset);
            }
            else
            {
                if (panLocation.X < 0)
                {
                    var proposedOffset = this.GetNextOffset(offset);

                    this.currentScrolledOffset = proposedOffset;
                }
                else
                {
                    var proposedOffset = this.GetPriorOffset(offset);

                    this.currentScrolledOffset = proposedOffset;
                }

                this.ScrollContent(this.currentScrolledOffset);
            }

            gestureRecognizer.SetTranslation(PointF.Empty, this.View);
        }
		// Shift the image's center by the pan amount
		void PanImage (UIPanGestureRecognizer gestureRecognizer)
		{
			AdjustAnchorPointForGestureRecognizer (gestureRecognizer);
			var image = gestureRecognizer.View;
			if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed) {
				var translation = gestureRecognizer.TranslationInView (View);
				image.Center = new PointF (image.Center.X + translation.X, image.Center.Y + translation.Y);
				// Reset the gesture recognizer's translation to {0, 0} - the next callback will get a delta from the current position.
				gestureRecognizer.SetTranslation (PointF.Empty, image);
			}
		}
Пример #26
0
		void SlideAndFix (UIPanGestureRecognizer gesture)
		{

			UIView piece = gesture.View;
			nfloat yComponent = piece.Superview.Center.Y - 40f;
			if (!ComponentExpanded || piece.Frame.Top < piece.Superview.Center.Y) {
				ComponentExpanded = true;

			} else {
				yComponent = piece.Superview.Frame.Height - 40f;
				ComponentExpanded = false;
			}

			UIImageView.Animate (
				duration: 0.25f, 
				delay: 0,
				options: UIViewAnimationOptions.TransitionNone,
				animation: () => {
					piece.Frame = new RectangleF (new PointF (piece.Frame.X, yComponent), piece.Frame.Size);

					gesture.SetTranslation (new PointF (0, 0), piece.Superview);
				},
				completion: () => {
					
				});			
		}
Пример #27
0
		void PanGestureMoveAround (UIPanGestureRecognizer gesture)
		{
			
			UIView piece = gesture.View;

			AdjustAnchorPointForGestureRecognizer (gesture);

			if (gesture.State == UIGestureRecognizerState.Began || gesture.State == UIGestureRecognizerState.Changed) {

				PointF translation = gesture.TranslationInView (piece.Superview);

				piece.Center = new PointF (piece.Center.X, piece.Center.Y + translation.Y);
				 
				gesture.SetTranslation (new PointF (0, 0), piece.Superview);

			} else if (gesture.State == UIGestureRecognizerState.Ended) {
				SlideAndFix (gesture);
			} 		
		}
Пример #28
0
        void panHandle(UIPanGestureRecognizer gestureRecognizer)
        {
            //AdjustAnchorPointForGestureRecognizer (gestureRecognizer);
            var image = gestureRecognizer.View;

            if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed)
            {
                var translation = gestureRecognizer.TranslationInView(this);
                //image.Center = new CGPoint (image.Center.X + translation.X, image.Center.Y);// + translation.Y

                nfloat delta = -1 * translation.X;
                if (isOpen)
                {
                    //left menu is active
                    if (swipe_delta < 0)
                    {
                        swipe_delta += (delta * 0.3f);
                    }
                    else if (swipe_delta < x - x_max)
                    {
                        swipe_delta += (delta * 0.3f);
                    }
                    else
                    {
                        swipe_delta += delta;
                    }
                    content.Frame = new CGRect(x_max - swipe_delta, y, w, h);
                }
                else
                {
                    //when is in the normal state
                    if (swipe_delta > 0)
                    {
                        swipe_delta += (delta * 0.7f);                         //navigate to nextview
                    }
                    else if (swipe_delta < (x - x_max))
                    {
                        swipe_delta += (delta * 0.3f);                         // stopping the menu
                    }
                    else
                    {
                        swipe_delta += delta;                       // to the menu
                    }
                    content.Frame = new CGRect(x - swipe_delta, y, w, h);
                }



                // Reset the gesture recognizer's translation to {0, 0} - the next callback will get a delta from the current position.
                gestureRecognizer.SetTranslation(CGPoint.Empty, this);
            }


            if (gestureRecognizer.State == UIGestureRecognizerState.Ended)
            {
                CGPoint velocity = gestureRecognizer.VelocityInView(this);
                //image.Center = new CGPoint (0,0);
                if (content.Frame.X > (x_max + x) / 2)
                {
                    OpenContent();
                }
                else if (content.Frame.X < -400)
                {
                    if (Navigate2ReaderStarted != null)
                    {
                        Navigate2ReaderStarted(this);
                    }



                    UIView.Animate(0.35, () => {
                        content.Frame      = new CGRect(-1 * w, y, w, h);
                        leftMenuView.Alpha = 0;
                    }, () => {
                        if (Navigate2Reader != null)
                        {
                            Navigate2Reader(this);
                        }
                    });
                }
                else
                {
                    CloseContent();
                }


                swipe_delta = 0;
            }
        }
Пример #29
0
        void moveLine(UIPanGestureRecognizer gr)
        {
            // if no line selected, do nothing
            if (selectedLine == null)
                return;

            // When the pan gesture recognizer changes its position...
            if (gr.State == UIGestureRecognizerState.Changed) {
                // How far has the pan moved?
                CGPoint translation = gr.TranslationInView(this);

                // Add the translation to the current begin and end points of the line
                CGPoint begin = selectedLine.begin;
                CGPoint end = selectedLine.end;
                begin.X += translation.X;
                begin.Y += translation.Y;
                end.X += translation.X;
                end.Y += translation.Y;

                // Set the new beginning and end points of the line
                selectedLine.begin = begin;
                selectedLine.end = end;

                LineStore.updateCompletedLine(selectedLine);

                this.SetNeedsDisplay();

                gr.SetTranslation(new CGPoint(0,0),this);
            } else if (gr.State == UIGestureRecognizerState.Ended) {
                selectedLine = null;
            }
        }
Пример #30
0
        private void ResizeRegionOfInterestWithGestureRecognizer(UIPanGestureRecognizer gestureRecognizer)
        {
            var touchLocation       = gestureRecognizer.LocationInView(gestureRecognizer.View);
            var oldRegionOfInterest = this.RegionOfInterest;

            switch (gestureRecognizer.State)
            {
            case UIGestureRecognizerState.Began:
                // When the gesture begins, save the corner that is closes to
                // the resize region of interest gesture recognizer's touch location.
                this.currentControlCorner = CornerOfRect(oldRegionOfInterest, touchLocation);
                break;


            case UIGestureRecognizerState.Changed:
                var newRegionOfInterest = oldRegionOfInterest;

                switch (this.currentControlCorner)
                {
                case ControlCorner.None:
                    // Update the new region of interest with the gesture recognizer's translation.
                    var translation = gestureRecognizer.TranslationInView(gestureRecognizer.View);

                    // Move the region of interest with the gesture recognizer's translation.
                    if (this.RegionOfInterest.Contains(touchLocation))
                    {
                        newRegionOfInterest.X += translation.X;
                        newRegionOfInterest.Y += translation.Y;
                    }

                    // If the touch location goes outside the preview layer,
                    // we will only translate the region of interest in the
                    // plane that is not out of bounds.
                    var normalizedRect = new CGRect(0, 0, 1, 1);
                    if (!normalizedRect.Contains(this.VideoPreviewLayer.PointForCaptureDevicePointOfInterest(touchLocation)))
                    {
                        if (touchLocation.X < RegionOfInterest.GetMinX() || touchLocation.X > RegionOfInterest.GetMaxX())
                        {
                            newRegionOfInterest.Y += translation.Y;
                        }
                        else if (touchLocation.Y < RegionOfInterest.GetMinY() || touchLocation.Y > RegionOfInterest.GetMaxY())
                        {
                            newRegionOfInterest.X += translation.X;
                        }
                    }

                    // Set the translation to be zero so that the new gesture
                    // recognizer's translation is in respect to the region of
                    // interest's new position.
                    gestureRecognizer.SetTranslation(CGPoint.Empty, gestureRecognizer.View);
                    break;

                case ControlCorner.TopLeft:
                    newRegionOfInterest = new CGRect(touchLocation.X, touchLocation.Y,
                                                     oldRegionOfInterest.Width + oldRegionOfInterest.X - touchLocation.X,
                                                     oldRegionOfInterest.Height + oldRegionOfInterest.Y - touchLocation.Y);
                    break;

                case ControlCorner.TopRight:
                    newRegionOfInterest = new CGRect(newRegionOfInterest.X,
                                                     touchLocation.Y,
                                                     touchLocation.X - newRegionOfInterest.X,
                                                     oldRegionOfInterest.Height + newRegionOfInterest.Y - touchLocation.Y);
                    break;


                case ControlCorner.BottomLeft:
                    newRegionOfInterest = new CGRect(touchLocation.X,
                                                     oldRegionOfInterest.Y,
                                                     oldRegionOfInterest.Width + oldRegionOfInterest.X - touchLocation.X,
                                                     touchLocation.Y - oldRegionOfInterest.Y);
                    break;

                case ControlCorner.BottomRight:
                    newRegionOfInterest = new CGRect(oldRegionOfInterest.X,
                                                     oldRegionOfInterest.Y,
                                                     touchLocation.X - oldRegionOfInterest.X,
                                                     touchLocation.Y - oldRegionOfInterest.Y);
                    break;
                }

                // Update the region of interest with a valid CGRect.
                this.SetRegionOfInterestWithProposedRegionOfInterest(newRegionOfInterest);
                break;

            case UIGestureRecognizerState.Ended:
                this.RegionOfInterestChanged?.Invoke(this, EventArgs.Empty);

                // Reset the current corner reference to none now that the resize.
                // gesture recognizer has ended.
                this.currentControlCorner = ControlCorner.None;
                break;

            default:
                return;
            }
        }
Пример #31
0
		void ResizeRegionOfInterestWithGestureRecognizer (UIPanGestureRecognizer pan)
		{
			var touchLocation = pan.LocationInView (pan.View);
			var oldRegionOfInterest = RegionOfInterest;

			switch (pan.State) {
			case UIGestureRecognizerState.Began:
				// When the gesture begins, save the corner that is closes to
				// the resize region of interest gesture recognizer's touch location.
				currentControlCorner = CornerOfRect (oldRegionOfInterest, touchLocation);
				break;


			case UIGestureRecognizerState.Changed:
				var newRegionOfInterest = oldRegionOfInterest;

				switch (currentControlCorner) {
				case ControlCorner.None:
					// Update the new region of interest with the gesture recognizer's translation.
					var translation = pan.TranslationInView (pan.View);
					// Move the region of interest with the gesture recognizer's translation.
					if (RegionOfInterest.Contains (touchLocation)) {
						newRegionOfInterest.X += translation.X;
						newRegionOfInterest.Y += translation.Y;
					}

					// If the touch location goes outside the preview layer,
					// we will only translate the region of interest in the
					// plane that is not out of bounds.
					var normalizedRect = new CGRect (0, 0, 1, 1);
					if (!normalizedRect.Contains (VideoPreviewLayer.PointForCaptureDevicePointOfInterest (touchLocation))) {
						if (touchLocation.X < RegionOfInterest.GetMinX () || touchLocation.X > RegionOfInterest.GetMaxX ()) {
							newRegionOfInterest.Y += translation.Y;
						} else if (touchLocation.Y < RegionOfInterest.GetMinY () || touchLocation.Y > RegionOfInterest.GetMaxY ()) {
							newRegionOfInterest.X += translation.X;
						}
					}

					// Set the translation to be zero so that the new gesture
					// recognizer's translation is in respect to the region of
					// interest's new position.
					pan.SetTranslation (CGPoint.Empty, pan.View);
					break;

				case ControlCorner.TopLeft:
					newRegionOfInterest = new CGRect (touchLocation.X, touchLocation.Y,
													 oldRegionOfInterest.Width + oldRegionOfInterest.X - touchLocation.X,
													 oldRegionOfInterest.Height + oldRegionOfInterest.Y - touchLocation.Y);
					break;

				case ControlCorner.TopRight:
					newRegionOfInterest = new CGRect (newRegionOfInterest.X,
												 touchLocation.Y,
												 touchLocation.X - newRegionOfInterest.X,
												 oldRegionOfInterest.Height + newRegionOfInterest.Y - touchLocation.Y);
					break;


				case ControlCorner.BottomLeft:
					newRegionOfInterest = new CGRect (touchLocation.X, oldRegionOfInterest.Y,
												 oldRegionOfInterest.Width + oldRegionOfInterest.X - touchLocation.X,
												 touchLocation.Y - oldRegionOfInterest.Y);
					break;

				case ControlCorner.BottomRight:
					newRegionOfInterest = new CGRect (oldRegionOfInterest.X, oldRegionOfInterest.Y,
												 touchLocation.X - oldRegionOfInterest.X,
												 touchLocation.Y - oldRegionOfInterest.Y);
					break;
				}

				// Update the region of intresest with a valid CGRect.
				SetRegionOfInterestWithProposedRegionOfInterest (newRegionOfInterest);
				break;

			case UIGestureRecognizerState.Ended:
				RegionOfInterestDidChange?.Invoke (this, EventArgs.Empty);

				// Reset the current corner reference to none now that the resize.
				// gesture recognizer has ended.
				currentControlCorner = ControlCorner.None;
				break;

			default:
				return;
			}
		}
Пример #32
0
        void PanGestureRecognized(UIPanGestureRecognizer recognizer)
        {
            //          if ([self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:didRecognizePanGesture:)])
            //              [self.delegate sideMenu:self didRecognizePanGesture:recognizer];

            if (!_panGestureEnabled)
            {
                return;
            }

            PointF point = recognizer.TranslationInView(View);

            if (recognizer.State == UIGestureRecognizerState.Began)
            {
                UpdateContentViewShadow();

                _originalPoint = new PointF((float)(_contentViewContainer.Center.X - _contentViewContainer.Bounds.Width / 2.0),
                                            (float)(_contentViewContainer.Center.Y - _contentViewContainer.Bounds.Height / 2.0));
                _menuViewContainer.Transform = CGAffineTransform.MakeIdentity();
                if (_scaleBackgroundImageView)
                {
                    _backgroundImageView.Transform = CGAffineTransform.MakeIdentity();
                    _backgroundImageView.Frame     = View.Bounds;
                }
                _menuViewContainer.Frame = View.Bounds;
                AddContentButton();
                View.Window.EndEditing(true);
                _didNotifyDelegate = false;
            }

            if (recognizer.State == UIGestureRecognizerState.Changed)
            {
                float delta = 0;
                if (Visible)
                {
                    delta = _originalPoint.X != 0 ? (point.X + _originalPoint.X) / _originalPoint.X : 0;
                }
                else
                {
                    delta = point.X / View.Frame.Size.Width;
                }
                delta = Math.Min(Math.Abs(delta), 1.6F);

                float contentViewScale = _scaleContentView ? 1 - ((1 - _contentViewScaleValue) * delta) : 1;

                float backgroundViewScale = 1.7f - (0.7f * delta);
                float menuViewScale       = 1.5f - (0.5f * delta);

                if (!_bouncesHorizontally)
                {
                    contentViewScale    = Math.Max(contentViewScale, _contentViewScaleValue);
                    backgroundViewScale = Math.Max(backgroundViewScale, 1.0F);
                    menuViewScale       = Math.Max(menuViewScale, 1.0F);
                }

                _menuViewContainer.Alpha = delta;

                if (_scaleBackgroundImageView)
                {
                    _backgroundImageView.Transform = CGAffineTransform.MakeScale(backgroundViewScale, backgroundViewScale);
                }

                if (_scaleMenuView)
                {
                    _menuViewContainer.Transform = CGAffineTransform.MakeScale(menuViewScale, menuViewScale);
                }

                if (_scaleBackgroundImageView)
                {
                    if (backgroundViewScale < 1)
                    {
                        _backgroundImageView.Transform = CGAffineTransform.MakeIdentity();
                    }
                }

                if (!_bouncesHorizontally && Visible)
                {
                    if (_contentViewContainer.Frame.Location.X > _contentViewContainer.Frame.Size.Width / 2.0)
                    {
                        point.X = Math.Min(0.0F, point.X);
                    }

                    if (_contentViewContainer.Frame.Location.X < -(_contentViewContainer.Frame.Size.Width / 2.0))
                    {
                        point.X = Math.Max(0.0F, point.X);
                    }
                }

                // Limit size
                //
                if (point.X < 0)
                {
                    point.X = Math.Max(point.X, -UIScreen.MainScreen.Bounds.Size.Height);
                }
                else
                {
                    point.X = Math.Min(point.X, UIScreen.MainScreen.Bounds.Size.Height);
                }
                recognizer.SetTranslation(point, View);

                if (!_didNotifyDelegate)
                {
                    if (point.X > 0)
                    {
                        //                      if (!Visible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:willShowMenuViewController:)]) {
                        //                          [self.delegate sideMenu:self willShowMenuViewController:self.leftMenuViewController];
                        //                      }
                    }
                    if (point.X < 0)
                    {
                        //                      if (!self.visible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:willShowMenuViewController:)]) {
                        //                          //[self.delegate sideMenu:self willShowMenuViewController:self.rightMenuViewController];
                        //                      }
                    }
                    _didNotifyDelegate = true;
                }

                if (contentViewScale > 1)
                {
                    float oppositeScale = (1 - (contentViewScale - 1));
                    _contentViewContainer.Transform = CGAffineTransform.MakeScale(oppositeScale, oppositeScale);
                    _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0);
                }
                else
                {
                    _contentViewContainer.Transform = CGAffineTransform.MakeScale(contentViewScale, contentViewScale);
                    _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0);
                }

                if (_leftMenuViewController != null)
                {
                    _leftMenuViewController.View.Hidden = _contentViewContainer.Frame.Location.X < 0;
                }
                if (_rightMenuViewController != null)
                {
                    _rightMenuViewController.View.Hidden = _contentViewContainer.Frame.Location.X > 0;
                }

                if (_leftMenuViewController == null && _contentViewContainer.Frame.Location.X > 0)
                {
                    _contentViewContainer.Transform = CGAffineTransform.MakeIdentity();
                    _contentViewContainer.Frame     = View.Bounds;
                    Visible          = false;
                    _leftMenuVisible = false;
                }
                else if (_rightMenuViewController == null && _contentViewContainer.Frame.Location.X < 0)
                {
                    _contentViewContainer.Transform = CGAffineTransform.MakeIdentity();
                    _contentViewContainer.Frame     = View.Bounds;
                    Visible           = false;
                    _rightMenuVisible = false;
                }

                StatusBarNeedsAppearanceUpdate();
            }

            if (recognizer.State == UIGestureRecognizerState.Ended)
            {
                _didNotifyDelegate = false;

                if (_leftMenuViewController != null)
                {
                    _leftMenuViewController.View.Hidden = false;
                }
                if (_rightMenuViewController != null)
                {
                    _rightMenuViewController.View.Hidden = false;
                }

                if (_panMinimumOpenThreshold > 0 && (
                        (_contentViewContainer.Frame.Location.X < 0 && _contentViewContainer.Frame.Location.X > -((int)_panMinimumOpenThreshold)) ||
                        (_contentViewContainer.Frame.Location.X > 0 && _contentViewContainer.Frame.Location.X < _panMinimumOpenThreshold))
                    )
                {
                    HideMenuViewController(this, null);
                }
                else if (_contentViewContainer.Frame.Location.X == 0)
                {
                    HideMenuViewControllerAnimated(false);
                }
                else
                {
                    if (recognizer.VelocityInView(View).X > 0)
                    {
                        if (_contentViewContainer.Frame.Location.X < 0)
                        {
                            HideMenuViewController(this, null);
                        }
                        else
                        {
                            if (_leftMenuViewController != null)
                            {
                                ShowLeftMenuViewController();
                            }
                        }
                    }
                    else
                    {
                        if (_contentViewContainer.Frame.Location.X < 20)
                        {
                            if (_rightMenuViewController != null)
                            {
                                ShowRightMenuViewController();
                            }
                        }
                        else
                        {
                            HideMenuViewController(this, null);
                        }
                    }
                }
            }
        }
Пример #33
0
        void PanGestureRecognized(UIPanGestureRecognizer recognizer)
        {
            //          if ([self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:didRecognizePanGesture:)])
            //              [self.delegate sideMenu:self didRecognizePanGesture:recognizer];

            if (!_panGestureEnabled) {
                return;
            }

            PointF point = recognizer.TranslationInView(View);

            if (recognizer.State == UIGestureRecognizerState.Began) {
                UpdateContentViewShadow();

                _originalPoint = new PointF((float)(_contentViewContainer.Center.X - _contentViewContainer.Bounds.Width / 2.0),
                    (float)(_contentViewContainer.Center.Y - _contentViewContainer.Bounds.Height / 2.0));
                _menuViewContainer.Transform = CGAffineTransform.MakeIdentity();
                if (_scaleBackgroundImageView) {
                    _backgroundImageView.Transform = CGAffineTransform.MakeIdentity();
                    _backgroundImageView.Frame = View.Bounds;
                }
                _menuViewContainer.Frame = View.Bounds;
                AddContentButton();
                View.Window.EndEditing(true);
                _didNotifyDelegate = false;
            }

            if (recognizer.State == UIGestureRecognizerState.Changed) {
                float delta = 0;
                if (Visible) {
                    delta = _originalPoint.X != 0 ? (point.X + _originalPoint.X) / _originalPoint.X : 0;
                } else {
                    delta = point.X / View.Frame.Size.Width;
                }
                delta = Math.Min(Math.Abs(delta), 1.6F);

                float contentViewScale = _scaleContentView ? 1 - ((1 - _contentViewScaleValue) * delta) : 1;

                float backgroundViewScale = 1.7f - (0.7f * delta);
                float menuViewScale = 1.5f - (0.5f * delta);

                if (!_bouncesHorizontally) {
                    contentViewScale = Math.Max(contentViewScale, _contentViewScaleValue);
                    backgroundViewScale = Math.Max(backgroundViewScale, 1.0F);
                    menuViewScale = Math.Max(menuViewScale, 1.0F);
                }

                _menuViewContainer.Alpha = delta;

                if (_scaleBackgroundImageView) {
                    _backgroundImageView.Transform = CGAffineTransform.MakeScale(backgroundViewScale, backgroundViewScale);
                }

                if (_scaleMenuView) {
                    _menuViewContainer.Transform = CGAffineTransform.MakeScale(menuViewScale, menuViewScale);
                }

                if (_scaleBackgroundImageView) {
                    if (backgroundViewScale < 1) {
                        _backgroundImageView.Transform = CGAffineTransform.MakeIdentity();
                    }
                }

                if (!_bouncesHorizontally && Visible) {
                    if (_contentViewContainer.Frame.Location.X > _contentViewContainer.Frame.Size.Width / 2.0)
                        point.X = Math.Min(0.0F, point.X);

                    if (_contentViewContainer.Frame.Location.X < -(_contentViewContainer.Frame.Size.Width / 2.0))
                        point.X = Math.Max(0.0F, point.X);
                }

                // Limit size
                //
                if (point.X < 0) {
                    point.X = Math.Max(point.X, - UIScreen.MainScreen.Bounds.Size.Height);
                } else {
                    point.X = Math.Min(point.X, UIScreen.MainScreen.Bounds.Size.Height);
                }
                recognizer.SetTranslation (point, View);

                if (!_didNotifyDelegate) {
                    if (point.X > 0) {
                        //                      if (!Visible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:willShowMenuViewController:)]) {
                        //                          [self.delegate sideMenu:self willShowMenuViewController:self.leftMenuViewController];
                        //                      }
                    }
                    if (point.X < 0) {

                        //                      if (!self.visible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:willShowMenuViewController:)]) {
                        //                          //[self.delegate sideMenu:self willShowMenuViewController:self.rightMenuViewController];
                        //                      }
                    }
                    _didNotifyDelegate = true;
                }

                if (contentViewScale > 1) {
                    float oppositeScale = (1 - (contentViewScale - 1));
                    _contentViewContainer.Transform = CGAffineTransform.MakeScale(oppositeScale, oppositeScale);
                    _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0);
                } else {
                    _contentViewContainer.Transform = CGAffineTransform.MakeScale(contentViewScale, contentViewScale);
                    _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0);
                }

                if (_leftMenuViewController != null)
                    _leftMenuViewController.View.Hidden = _contentViewContainer.Frame.Location.X < 0;
                if (_rightMenuViewController != null)
                    _rightMenuViewController.View.Hidden = _contentViewContainer.Frame.Location.X > 0;

                if (_leftMenuViewController == null && _contentViewContainer.Frame.Location.X > 0) {
                    _contentViewContainer.Transform = CGAffineTransform.MakeIdentity();
                    _contentViewContainer.Frame = View.Bounds;
                    Visible = false;
                    _leftMenuVisible = false;
                } else  if (_rightMenuViewController == null && _contentViewContainer.Frame.Location.X < 0) {
                    _contentViewContainer.Transform = CGAffineTransform.MakeIdentity();
                    _contentViewContainer.Frame = View.Bounds;
                    Visible = false;
                    _rightMenuVisible = false;
                }

                StatusBarNeedsAppearanceUpdate ();
            }

            if (recognizer.State == UIGestureRecognizerState.Ended) {
                _didNotifyDelegate = false;

                if (_leftMenuViewController != null)
                    _leftMenuViewController.View.Hidden = false;
                if (_rightMenuViewController != null)
                    _rightMenuViewController.View.Hidden = false;

                if (_panMinimumOpenThreshold > 0 && (
                    (_contentViewContainer.Frame.Location.X < 0 && _contentViewContainer.Frame.Location.X > -((int)_panMinimumOpenThreshold)) ||
                    (_contentViewContainer.Frame.Location.X > 0 && _contentViewContainer.Frame.Location.X < _panMinimumOpenThreshold))
                ) {
                    HideMenuViewController (this, null);
                }
                else if (_contentViewContainer.Frame.Location.X == 0) {
                    HideMenuViewControllerAnimated(false);
                }
                else {
                    if (recognizer.VelocityInView(View).X > 0) {
                        if (_contentViewContainer.Frame.Location.X < 0) {
                            HideMenuViewController (this, null);
                        } else {
                            if (_leftMenuViewController != null) {
                                ShowLeftMenuViewController ();
                            }
                        }
                    } else {
                        if (_contentViewContainer.Frame.Location.X < 20) {
                            if (_rightMenuViewController != null) {
                                ShowRightMenuViewController ();
                            }
                        } else {
                            HideMenuViewController (this, null);
                        }
                    }
                }
            }
        }
Пример #34
0
        private void PanGestureRecognized(UIPanGestureRecognizer recognizer)
        {
            DidRecognizePanGesture?.Invoke(this, recognizer);

            if (!PanGestureEnabled)
            {
                return;
            }
            try
            {
                var point = recognizer.TranslationInView(View);

                if (recognizer.State == UIGestureRecognizerState.Began)
                {
                    UpdateContentViewShadow();
                    _originalPoint = new CGPoint(_contentViewContainer.Center.X - _contentViewContainer.Bounds.Width / 2.0,
                                                 _contentViewContainer.Center.Y - _contentViewContainer.Bounds.Height / 2.0);
                    _menuViewContainer.Transform = CGAffineTransform.MakeIdentity();
                    if (ScaleBackgroundImageView)
                    {
                        _backgroundImageView.Transform = CGAffineTransform.MakeIdentity();
                        _backgroundImageView.Frame     = View.Bounds;
                    }
                    _menuViewContainer.Frame = View.Bounds;
                    AddContentButton();
                    View.Window.EndEditing(true);
                    _didNotifyDelegate = false;
                }

                if (recognizer.State == UIGestureRecognizerState.Changed)
                {
                    nfloat delta = 0;
                    if (_visible)
                    {
                        delta = _originalPoint.X != 0 ? (point.X + _originalPoint.X) / _originalPoint.X : 0;
                    }
                    else
                    {
                        delta = point.X / View.Frame.Width;
                    }
                    delta = Math.Min(Math.Abs((float)delta), 1.6f);

                    var contentViewScale = ScaleContentView ? 1 - ((1 - ContentViewScaleValue) * delta) : 1;

                    var backgroundViewScale = 1.7f - (0.7f * delta);
                    var menuViewScale       = 1.5f - (0.5f * delta);

                    if (!BouncesHorizontally)
                    {
                        contentViewScale    = Math.Max((float)contentViewScale, ContentViewScaleValue);
                        backgroundViewScale = Math.Max((float)backgroundViewScale, 1.0f);
                        menuViewScale       = Math.Max((float)menuViewScale, 1.0f);
                    }

                    _menuViewContainer.Alpha    = !FadeMenuView ? 0 : delta;
                    _contentViewContainer.Alpha = 1 - (1 - ContentViewFadeOutAlpha) * delta;

                    if (ScaleBackgroundImageView)
                    {
                        _backgroundImageView.Transform = CGAffineTransform.MakeScale(backgroundViewScale, backgroundViewScale);
                    }

                    if (ScaleMenuView)
                    {
                        _menuViewContainer.Transform = CGAffineTransform.MakeScale(menuViewScale, menuViewScale);
                    }

                    if (ScaleBackgroundImageView)
                    {
                        if (backgroundViewScale < 1)
                        {
                            _backgroundImageView.Transform = CGAffineTransform.MakeIdentity();
                        }
                    }

                    if (!BouncesHorizontally && _visible)
                    {
                        if (_contentViewContainer.Frame.X > _contentViewContainer.Frame.Width / 2.0)
                        {
                            point.X = Math.Min(0.0f, (float)point.X);
                        }

                        if (_contentViewContainer.Frame.X < -(_contentViewContainer.Frame.Width / 2.0))
                        {
                            point.X = Math.Max(0.0f, (float)point.X);
                        }
                    }

                    // Limit size
                    //
                    if (point.X < 0)
                    {
                        point.X = Math.Max((float)point.X, (float)-UIScreen.MainScreen.Bounds.Height);
                    }
                    else
                    {
                        point.X = Math.Min((float)point.X, (float)UIScreen.MainScreen.Bounds.Height);
                    }
                    recognizer.SetTranslation(point, View);

                    if (!_didNotifyDelegate)
                    {
                        if (point.X > 0)
                        {
                            if (!_visible)
                            {
                                _menuState = MenuState.LeftOpening;
                                WillShowMenuViewController?.Invoke(this, LeftMenuViewController);
                            }
                            else
                            {
                                _menuState = MenuState.RightClosing;
                            }
                        }
                        if (point.X < 0)
                        {
                            if (!_visible)
                            {
                                _menuState = MenuState.RightOpening;
                                WillShowMenuViewController?.Invoke(this, RightMenuViewController);
                            }
                            else
                            {
                                _menuState = MenuState.LeftClosing;
                            }
                        }
                        _didNotifyDelegate = true;
                    }

                    if (contentViewScale > 1)
                    {
                        var oppositeScale = (1 - (contentViewScale - 1));
                        _contentViewContainer.Transform = CGAffineTransform.MakeScale(oppositeScale, oppositeScale);
                        _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0);
                    }
                    else
                    {
                        _contentViewContainer.Transform = CGAffineTransform.MakeScale(contentViewScale, contentViewScale);
                        _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0);
                    }

                    if (LeftMenuViewController != null)
                    {
                        LeftMenuViewController.View.Hidden = _contentViewContainer.Frame.X < 0;
                    }
                    if (RightMenuViewController != null)
                    {
                        RightMenuViewController.View.Hidden = _contentViewContainer.Frame.X > 0;
                    }

                    if (LeftMenuViewController == null && _contentViewContainer.Frame.X > 0)
                    {
                        _contentViewContainer.Transform = CGAffineTransform.MakeIdentity();
                        _contentViewContainer.Frame     = View.Bounds;
                        _visible        = false;
                        LeftMenuVisible = false;
                    }
                    else if (RightMenuViewController == null && _contentViewContainer.Frame.X < 0)
                    {
                        _contentViewContainer.Transform = CGAffineTransform.MakeIdentity();
                        _contentViewContainer.Frame     = View.Bounds;
                        _visible         = false;
                        RightMenuVisible = false;
                    }
                    StatusBarNeedsAppearanceUpdate();
                }
                if (recognizer.State == UIGestureRecognizerState.Ended)
                {
                    _didNotifyDelegate = false;
                    if (PanMinimumOpenThreshold > 0 && (
                            (_contentViewContainer.Frame.X < 0 && _contentViewContainer.Frame.X > -((int)PanMinimumOpenThreshold)) ||
                            (_contentViewContainer.Frame.X > 0 && _contentViewContainer.Frame.X < PanMinimumOpenThreshold))
                        )
                    {
                        HideMenuViewController();
                    }
                    else if (_contentViewContainer.Frame.X == 0)
                    {
                        HideMenuViewControllerAnimated(false);
                    }
                    else
                    {
                        if (recognizer.VelocityInView(View).X > 0)
                        {
                            if (_contentViewContainer.Frame.X < 0)
                            {
                                HideMenuViewController();
                            }
                            else
                            {
                                if (LeftMenuViewController != null)
                                {
                                    ShowLeftMenuViewController();
                                }
                            }
                        }
                        else
                        {
                            if (_contentViewContainer.Frame.X < 20)
                            {
                                if (RightMenuViewController != null)
                                {
                                    ShowRightMenuViewController();
                                }
                            }
                            else
                            {
                                HideMenuViewController();
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception :" + e);
                System.Diagnostics.Debug.WriteLine("Stacktrace :" + e.StackTrace);
            }
        }
Пример #35
0
        void HandleDrag(UIPanGestureRecognizer sender)
        {
            switch (sender.State)
            {
                case UIGestureRecognizerState.Began:
                    startPos = this.Center;
                // Determines if the view can be pulled in the x or y axis
                    verticalAxis = closedCenter.X == openedCenter.X;
                // Finds the minimum and maximum points in the axis
                    if (verticalAxis)
                    {
                        minPos = closedCenter.Y < openedCenter.Y ? closedCenter : openedCenter;
                        maxPos = closedCenter.Y > openedCenter.Y ? closedCenter : openedCenter;
                    }
                    else
                    {
                        minPos = closedCenter.X < openedCenter.X ? closedCenter : openedCenter;
                        maxPos = closedCenter.X > openedCenter.X ? closedCenter : openedCenter;
                    }
                    break;
                case UIGestureRecognizerState.Changed:
                    PointF translate = sender.TranslationInView(this.Superview);
                    PointF newPos;
                // Moves the view, keeping it constrained between openedCenter and closedCenter
                    if (verticalAxis)
                    {
                        newPos = new PointF(startPos.X, startPos.Y + translate.Y);
                        if (newPos.Y < minPos.Y)
                        {
                            newPos.Y = minPos.Y;
                            translate = new PointF(0, newPos.Y - startPos.Y);
                        }

                        if (newPos.Y > maxPos.Y)
                        {
                            newPos.Y = maxPos.Y;
                            translate = new PointF(0, newPos.Y - startPos.Y);
                        }

                    }
                    else
                    {
                        newPos = new PointF(startPos.X + translate.X, startPos.Y);
                        if (newPos.X < minPos.X)
                        {
                            newPos.X = minPos.X;
                            translate = new PointF(newPos.X - startPos.X, 0);
                        }

                        if (newPos.X > maxPos.X)
                        {
                            newPos.X = maxPos.X;
                            translate = new PointF(newPos.X - startPos.X, 0);
                        }
                    }

                    sender.SetTranslation(translate, this.Superview);
                    this.Center = newPos;
                    break;
                case UIGestureRecognizerState.Ended:
                    PointF vectorVelocity = sender.VelocityInView(this.Superview);
                    float axisVelocity = verticalAxis ? vectorVelocity.Y : vectorVelocity.X;
                    PointF target = axisVelocity < 0 ? minPos : maxPos;
                    bool op = target == openedCenter ? true : false;
                    this.SetOpenedAnimated(op, animate);
                    break;
            }
        }
Пример #36
0
        public void PanGestureUpdated(UIPanGestureRecognizer panGesture)
        {
            switch (panGesture.State)
            {
                case UIGestureRecognizerState.Ended:
                case UIGestureRecognizerState.Cancelled:
                case UIGestureRecognizerState.Failed:
                {
                    // TODO:  wtf is this?
                    //[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(transformingGestureDidFinish) object:nil];
                    Selector sel = new Selector("transformingGestureDidFinish");
                    PerformSelector(sel,null,0.1);

                    ScrollEnabled = true;

                } break;
                case UIGestureRecognizerState.Began:
                {
                    TransformingGestureDidBeginWithGesture(panGesture);

                    ScrollEnabled = false;

                } break;
                case UIGestureRecognizerState.Changed:
                {
                    if (panGesture.NumberOfTouches != 2)
                    {
                        panGesture.End();
                    }

                    PointF translate = panGesture.TranslationInView(this);
                    transformingItem.ContentView.Center = new PointF(transformingItem.ContentView.Center.X + translate.X, transformingItem.ContentView.Center.Y + translate.Y);
                    panGesture.SetTranslation(new PointF(),this);

                } break;
                default:
                {
                } break;
            }
        }