Example #1
0
        public void Transform(Matrix matrix)
        {
            if (!regionPath.IsEmpty && !regionBounds.Equals(infinite))
            {
                foreach (var path in solution)
                {
                    for (int p = 0; p < path.Count; p++)
                    {
                        var point = path [p];
                        TransformIntPoint(ref point, matrix);
                        path [p] = point;
                    }
                }

                PathsToInternalPath(solution);
            }
        }
Example #2
0
        public override void LayoutSubviews()
        {
            base.LayoutSubviews();
            var newFrame = new CGRect(x: 0, y: 0, width: UIScreen.MainScreen.Bounds.Width,
                                      height: UIScreen.MainScreen.Bounds.Height);

            if (!newFrame.Equals(Frame))
            {
                Frame = newFrame;
                //            InitViews(true);
                LayoutIfNeeded();
                UpdateViewFrames();
            }

            //            Show(false);
        }
        /// <summary>
        /// Sets up a drag recongniser on this view, so it can be moved/dragged.
        /// </summary>
        /// <param name="BoundedBySuperview">
        /// If set to <c>true</c> this frame cannot move past its parents frame boundary</param>
        public void DragPanGestureRecognizer(bool BoundedBySuperview)
        {
            // create a new tap gesture
            UIPanGestureRecognizer MovePadPanGesture = null;

            Action <UIPanGestureRecognizer> actGesture = (pg) =>
            {
                System.nfloat x;
                System.nfloat y;

                CGPoint _nextMove;

                AspyView _view = pg.View as AspyView;

                // Get the last touched position in the swipe
                _view.DragTranslationPoint = pg.TranslationInView(this.View.Superview);


                if (pg.State == UIGestureRecognizerState.Began)
                {
                    // Calc the allowed area for a drag
                    _view.DragValidFrame = new CGRect(
                        (_view.Frame.Width / 2),
                        (_view.Frame.Height / 2),
                        (_view.Superview.Frame.Width - _view.Frame.Width),
                        (_view.Superview.Frame.Height - _view.Frame.Height));
                    _view.DragStartPoint      = pg.LocationInView(_view);
                    _view.DragLastCenterPoint = this.View.Center;
                    return;
                }

                if (pg.State == UIGestureRecognizerState.Cancelled)
                {
                    this.View.Alpha = 1.0f;
                    return;
                }

                if (pg.State == UIGestureRecognizerState.Ended)
                {
                    //_animate();
                    this.View.Alpha = 1.0f;
                    return;
                }

                if ((Math.Abs(_view.DragTranslationPoint.X) <= 1.0 && Math.Abs(_view.DragTranslationPoint.Y) <= 1.0))
                {
                    return; // Ignore very small movements
                }


                if (BoundedBySuperview)
                {
                    System.nfloat  m           = 0.0f;
                    System.nfloat  n           = 0.0f;
                    System.Boolean bRight      = false;
                    System.Boolean bLeft       = false;
                    System.Boolean bTop        = false;
                    System.Boolean bBottom     = false;
                    CGRect         _superFrame = this.View.Superview.Frame;
                    // Create a new Rect based on the boundary variables crossed
                    CGRect _intersect = CGRect.Intersect(_superFrame, this.View.Frame);
                    if (!CGRect.Equals(_intersect, this.View.Frame))
                    {
                        m = _intersect.X + _intersect.Width;
                        n = _intersect.Y + _intersect.Height;
                        if (_superFrame.Width <= m)
                        {
                            // Hit the right
                            bRight = true;
                        }
                        if (_intersect.X <= 0)
                        {
                            // Hit the Left
                            bLeft = true;
                        }
                        if (_intersect.Y <= 0)
                        {
                            // Hit the Top
                            bTop = true;
                        }
                        if (_superFrame.Height <= n)
                        {
                            // Hit the Bottom
                            bBottom = true;
                        }
                        _view.DragCrossedSuperView = true;
                    }
                    else
                    {
                        _view.DragCrossedSuperView = false;
                    }
                }

                if (_view.DragVerticallyOnly)
                {
                    x = _view.Frame.X;
                }
                else
                {
                    x = _view.DragTranslationPoint.X + _view.DragLastCenterPoint.X;
                }

                if (_view.DragHorizontallyOnly)
                {
                    y = _view.Frame.Y;
                }
                else
                {
                    y = _view.DragTranslationPoint.Y + _view.DragLastCenterPoint.Y;
                }

                _nextMove = new CGPoint(x, y);

                Action _animate = () =>
                {
                    this.View.Alpha = 0.3f;

                    if (!BoundedBySuperview)
                    {
                        _view.Center = _nextMove;
                    }
                    if (_view.DragValidFrame.Contains(_nextMove))
                    {
                        _view.Center = _nextMove;
                    }
                };

                // You can use animation here.
                // But Im unsure if its any better/faster/responsive then simply redefining the center.

                UIView.Animate(0.1, _animate);
                //_animate();
            };

            MovePadPanGesture = new UIPanGestureRecognizer(actGesture);
            // Test to see how it work with one finger.
            MovePadPanGesture.MaximumNumberOfTouches = 1;
            MovePadPanGesture.MinimumNumberOfTouches = 1;

            // add the gesture recognizer to the view
            this.View.AddGestureRecognizer(MovePadPanGesture);
        }