public void RevealGesture(UIPanGestureRecognizer recognizer)
        {
            MenuViewController rearVC = (MenuViewController)SidebarViewController;
            rearVC.searchBar.ResignFirstResponder ();

            base.DragContentView (recognizer);
        }
Example #2
0
        /// <summary>
        /// Start scrolling
        /// Enables the scrolling by observing a view
        /// </summary>
        /// <param name="scrollableView">The view with the scrolling content that will be observed.</param>
        /// <param name="delay">The delay expressed in points that determines the scrolling resistance. Defaults to `0`.</param>
        public void FollowScrollView(UIView scrollableView, double delay = 0)
        {
            this.scrollableView = scrollableView;

            var recognizer = new UIPanGestureRecognizer(OnPan);

            recognizer.ShouldRecognizeSimultaneously = delegate {
                // Enables the scrolling of both the content and the navigation bar
                return(true);
            };
            recognizer.ShouldReceiveTouch = delegate {
                // Only scrolls the navigation bar with the content when `scrollingEnabled` is true
                return(ScrollingEnabled);
            };
            recognizer.MaximumNumberOfTouches = 1;

            gestureRecognizer = recognizer;
            scrollableView.AddGestureRecognizer(gestureRecognizer);

            didBecomeActiveObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidBecomeActiveNotification, notification => {
                if (ExpandOnActive)
                {
                    ShowNavbar(false);
                }
            });
            deviceOrientationDidChange = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidBecomeActiveNotification, notification => {
                ShowNavbar();
            });

            maxDelay         = (nfloat)delay;
            delayDistance    = (nfloat)delay;
            ScrollingEnabled = true;
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			_panGesture = new UIPanGestureRecognizer(PanGestureRecognized);
			View.AddGestureRecognizer(_panGesture);
		}
        private void AddGestures()
        {
            var touchDownGesture = new UILongPressGestureRecognizer(HandleTouchDown) { MinimumPressDuration = 0 };
            _canvasView.AddGestureRecognizer(touchDownGesture);

            // Tap to select
            var tapGesture = new UITapGestureRecognizer(HandleTap);
            _canvasView.AddGestureRecognizer(tapGesture);

            // Move an element
            var elementDragGesture = new UIPanGestureRecognizer(HandlePan);
            _canvasView.AddGestureRecognizer(elementDragGesture);

            elementDragGesture.ShouldBegin = g => _panShouldBegin;

            var selectLongPressGesture = new UILongPressGestureRecognizer(HandleLongPress) { MinimumPressDuration = 0.1 };
            _canvasView.AddGestureRecognizer(selectLongPressGesture);

            selectLongPressGesture.ShouldReceiveTouch = (g, touch) =>
            {
                var locationInCanvas = touch.LocationInView(_canvasView);
                var touchedElement = ElementUnderPoint(locationInCanvas);

                return touchedElement != null && !IsElementSelected(touchedElement);
            };

            selectLongPressGesture.ShouldRecognizeSimultaneously = (g1, g2) => g2 == elementDragGesture;
            touchDownGesture.ShouldRecognizeSimultaneously = (g1, g2) => true;
        }
		void HandlePanGesture (UIPanGestureRecognizer gesture)
		{
			if (gesture.State == UIGestureRecognizerState.Began) {
				gestureStartingPoint = gesture.TranslationInView (textView);
				gestureStartingCenter = imageView.Center;
			}
			else if (gesture.State == UIGestureRecognizerState.Changed) {
				CGPoint currentPoint = gesture.TranslationInView(textView);
				nfloat distanceX = currentPoint.X - gestureStartingPoint.X;
				nfloat distanceY = currentPoint.Y - gestureStartingPoint.Y;

				CGPoint newCenter = gestureStartingCenter;

				newCenter.X += distanceX;
				newCenter.Y += distanceY;

				imageView.Center = newCenter;

				textView.TextContainer.ExclusionPaths = TranslatedBezierPath ();
			}
			else if (gesture.State == UIGestureRecognizerState.Ended) {
				gestureStartingPoint  = new CGPoint (0, 0);
				gestureStartingCenter = new CGPoint (0, 0);
			}
		}
        public BMarkerImageView(WeakReference parentView, CGPoint location)
        {
            WeakParent = parentView;
             _location = location;

             UserInteractionEnabled = true;

             Frame = new CGRect (Location.X - 22, Location.Y - 22, 44, 44);
             using (var image = UIImage.FromFile ("Images/icon_marker.png"))
             {
            Image = image;
             }

             _pan = new UIPanGestureRecognizer (() =>
             {
            if ((_pan.State == UIGestureRecognizerState.Began || _pan.State == UIGestureRecognizerState.Changed) && (_pan.NumberOfTouches == 1))
            {
               Center = _pan.LocationInView (_parent);
               Location = Center;
               _parent.SetNeedsDisplay ();
            }
            else if (_pan.State == UIGestureRecognizerState.Ended)
            {
            }
             });

             _doubleTap = new UITapGestureRecognizer ((gesture) => Crop ()) {
            NumberOfTapsRequired = 2, NumberOfTouchesRequired = 1
             };

             AddGestureRecognizer (_pan);
             AddGestureRecognizer (_doubleTap);
        }
Example #7
0
        public RangeSlider()
        {
            _background = new UIView();
            _background.BackgroundColor = UIColor.LightGray;

            _range = new UIView();
            _range.BackgroundColor = UIColor.Blue;

            _leftIndicator = CreateIndicator();
            _leftIndicatorGesture = new UIPanGestureRecognizer(OnPan);

            _rightIndicator = CreateIndicator();
            _rightIndicatorGesture = new UIPanGestureRecognizer(OnPan);

            _leftTouchArea = new UIView();
            _leftTouchArea.BackgroundColor = UIColor.Clear;
            _leftTouchArea.AddGestureRecognizer(_leftIndicatorGesture);

            _rightTouchArena = new UIView();
            _rightTouchArena.BackgroundColor = UIColor.Clear;
            _rightTouchArena.AddGestureRecognizer(_rightIndicatorGesture);

            AddSubview(_background);
            AddSubview(_range);
            AddSubview(_leftIndicator);
            AddSubview(_rightIndicator);
            AddSubview(_leftTouchArea);
            AddSubview(_rightTouchArena);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SlideoutNavigationController"/> class.
        /// </summary>
        public SlideoutNavigationController()
        {
            SlideSpeed = 0.2f;
            SlideWidth = 260f;
            SlideHeight = 44f;
            LayerShadowing = true;

            _internalMenuView = new ProxyNavigationController
                                    {
                                        ParentController = this,
                                        View = { AutoresizingMask = UIViewAutoresizing.FlexibleHeight }
                                    };
            //_internalMenuView.SetNavigationBarHidden(true, false);

            _internalTopView = new UIViewController { View = { UserInteractionEnabled = true } };
            _internalTopView.View.Layer.MasksToBounds = false;

            _tapGesture = new UITapGestureRecognizer();
            //            _tapGesture.AddTarget(new )
            _tapGesture.AddTarget(Hide);
            _tapGesture.NumberOfTapsRequired = 1;

            _panGesture = new UIPanGestureRecognizer
                              {
                                  Delegate = new SlideoutPanDelegate(this),
                                  MaximumNumberOfTouches = 1,
                                  MinimumNumberOfTouches = 1
                              };
            _panGesture.AddTarget(() => Pan(_internalTopView.View));
            _internalTopView.View.AddGestureRecognizer(_panGesture);
        }
        private void CreatePanGestureRecognizer()
        {
            panGesture = new UIPanGestureRecognizer(() =>
            {
                if ((panGesture.State == UIGestureRecognizerState.Began || panGesture.State == UIGestureRecognizerState.Changed) && (panGesture.NumberOfTouches == 1))
                {

                    var p0 = panGesture.LocationInView(this);

                    if (dx == 0)
                        dx = p0.X - Subviews[0].Center.X;

                    if (dy == 0)
                        dy = p0.Y - Subviews[0].Center.Y;

                    var p1 = new PointF((float)(p0.X - dx), (float)(p0.Y - dy));

                    Subviews[0].Center = p1;
                }
                else if (panGesture.State == UIGestureRecognizerState.Ended)
                {
                    dx = 0;
                    dy = 0;
                }
            });
        }
Example #10
0
        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

            View.Apply (Style.Screen);
            NavigationBar.Apply (Style.NavigationBar);
            Delegate = new NavDelegate ();

            panGesture = new UIPanGestureRecognizer (OnPanGesture) {
                // TODO: TableView scroll gestures are not
                // compatible with the open / close pan gesture.
                ShouldRecognizeSimultaneously = (a, b) => ! (b.View is UITableView),
                CancelsTouchesInView = true,
            };
            View.AddGestureRecognizer (panGesture);

            fadeView = new UIView();
            fadeView.BackgroundColor = UIColor.FromRGBA (29f / 255f, 29f / 255f, 28f / 255f, 0.5f);
            fadeView.Frame = new CGRect (0, 0, View.Frame.Width, View.Frame.Height);
            fadeView.Hidden = true;

            tapGesture = new UITapGestureRecognizer (CloseMenu) {
                ShouldReceiveTouch = (a, b) => true,
                ShouldRecognizeSimultaneously = (a, b) => true,
                CancelsTouchesInView = true,
            };
            fadeView.AddGestureRecognizer (tapGesture);
            View.Add (fadeView);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SlideoutNavigationController"/> class.
        /// </summary>
        public SlideoutNavigationController()
        {
            SlideSpeed = 0.2f;
            SlideWidth = 245f;
            // HACK to detect pan gesture from the whole viewport
            SlideHeight = float.MaxValue;
            LayerShadowing = false;

            _internalMenuViewLeft = new ProxyNavigationController {
                ParentController = this,
                View = { AutoresizingMask = UIViewAutoresizing.FlexibleHeight }
            };
            _internalMenuViewRight = new ProxyNavigationController {
                ParentController = this,
                View = { AutoresizingMask = UIViewAutoresizing.FlexibleHeight }
            };

            _internalMenuViewLeft.SetNavigationBarHidden (DisplayNavigationBarOnLeftMenu, false);
            _internalMenuViewRight.SetNavigationBarHidden (DisplayNavigationBarOnRightMenu, false);

            _internalTopView = new UIViewController { View = { UserInteractionEnabled = true } };
            _internalTopView.View.Layer.MasksToBounds = false;

            _tapGesture = new UITapGestureRecognizer ();
            _tapGesture.AddTarget (() => Hide ());
            _tapGesture.NumberOfTapsRequired = 1;

            _panGesture = new UIPanGestureRecognizer {
                Delegate = new SlideoutPanDelegate(this),
                MaximumNumberOfTouches = 1,
                MinimumNumberOfTouches = 1
            };
            _panGesture.AddTarget (() => Pan (_internalTopView.View));
            _internalTopView.View.AddGestureRecognizer (_panGesture);
        }
        private void createGrab()
        {
            float dx = 0;
                var panGesture = new UIPanGestureRecognizer ((pg) => {
                    if ((pg.State == UIGestureRecognizerState.Began || pg.State == UIGestureRecognizerState.Changed) && (pg.NumberOfTouches == 1)) {

                        var p0 = pg.LocationInView (content);

                        if (dx == 0)
                            dx = p0.X - content.Center.X;

                        var p1 = new PointF (p0.X - dx, content.Center.Y);
                    //Dont let it go to far right
                        if (p1.X <= content.Center.X)
                            content.Center = p1;
                    //Auto withdrawl after 33%
                        if (p1.X < content.Frame.Width/3) {
                        closeIt();
                        }
                    } else if (pg.State == UIGestureRecognizerState.Ended) {
                        dx = 0;
                    }
                });
                content.AddGestureRecognizer (panGesture);
        }
        public override void ViewDidAppear(bool animated)
        {
            base.ViewWillAppear (animated);

            UINavigationController nav = NavigationController;
            MainViewController controller = (MainViewController)nav.ParentViewController; // MainViewController : ZUUIRevealController

            // Check if a UIPanGestureRecognizer already sits atop our NavigationBar.
            if (nav.NavigationBar.GestureRecognizers == null ||
                !(nav.NavigationBar.GestureRecognizers.Contains (navigationBarPanGestureRecognizer))) {
                // If not, allocate one and add it.
                UIPanGestureRecognizer panGestureRecognizer = new UIPanGestureRecognizer (controller.RevealGesture);
                navigationBarPanGestureRecognizer = panGestureRecognizer;

                NavigationController.NavigationBar.AddGestureRecognizer (navigationBarPanGestureRecognizer);
            }

            // Check if we have a revealButton already.
            if (NavigationItem.LeftBarButtonItem == null) {
                // If not, allocate one and add it.
                UIImage imageMenu = UIImage.FromFile ("action_menu.png");
                UIButton menuButton = new UIButton (UIButtonType.Custom);
                menuButton.SetImage (imageMenu, UIControlState.Normal);
                menuButton.Frame = new RectangleF (0.0f, 0.0f, (float)imageMenu.Size.Width, (float)imageMenu.Size.Height);
                menuButton.TouchUpInside += (sender, e) => controller.RevealToggle ();

                NavigationItem.LeftBarButtonItem = new UIBarButtonItem (menuButton);
            }
        }
Example #14
0
        public TouchDrawView(CGRect rect)
            : base(rect)
        {
            linesInProcess = new Dictionary<string, Line>();
            this.BackgroundColor = UIColor.White;
            this.MultipleTouchEnabled = true;

            UITapGestureRecognizer tapRecognizer = new UITapGestureRecognizer(tap);
            this.AddGestureRecognizer(tapRecognizer);

            UITapGestureRecognizer dbltapRecognizer = new UITapGestureRecognizer(dblTap);
            dbltapRecognizer.NumberOfTapsRequired = 2;
            this.AddGestureRecognizer(dbltapRecognizer);

            UILongPressGestureRecognizer pressRecognizer = new UILongPressGestureRecognizer(longPress);
            this.AddGestureRecognizer(pressRecognizer);

            moveRecognizer = new UIPanGestureRecognizer(moveLine);
            moveRecognizer.WeakDelegate = this;
            moveRecognizer.CancelsTouchesInView = false;
            this.AddGestureRecognizer(moveRecognizer);

            UISwipeGestureRecognizer swipeRecognizer = new UISwipeGestureRecognizer(swipe);
            swipeRecognizer.Direction = UISwipeGestureRecognizerDirection.Up;
            swipeRecognizer.NumberOfTouchesRequired = 3;
            this.AddGestureRecognizer(swipeRecognizer);

            selectedColor = UIColor.Red;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            nfloat r  = 0;
            nfloat dx = 0;
            nfloat dy = 0;

            using (var image = UIImage.FromFile("monkey.png")) {
                imageView = new UIImageView(image)
                {
                    Frame = new CGRect(new CGPoint(0, 0), image.Size)
                };
                imageView.UserInteractionEnabled = true;
                View.AddSubview(imageView);
            }
            rotateGesture = new UIRotationGestureRecognizer((() => {
                if ((rotateGesture.State == UIGestureRecognizerState.Began || rotateGesture.State == UIGestureRecognizerState.Changed) && (rotateGesture.NumberOfTouches == 2))
                {
                    imageView.Transform = CGAffineTransform.MakeRotation(rotateGesture.Rotation + r);
                }
                else if (rotateGesture.State == UIGestureRecognizerState.Ended)
                {
                    r += rotateGesture.Rotation;
                }
            }));


            panGesture = new UIPanGestureRecognizer(() => {
                if ((panGesture.State == UIGestureRecognizerState.Began || panGesture.State == UIGestureRecognizerState.Changed) && (panGesture.NumberOfTouches == 1))
                {
                    var p0 = panGesture.LocationInView(View);

                    if (dx == 0)
                    {
                        dx = p0.X - imageView.Center.X;
                    }

                    if (dy == 0)
                    {
                        dy = p0.Y - imageView.Center.Y;
                    }

                    var p1 = new CGPoint(p0.X - dx, p0.Y - dy);

                    imageView.Center = p1;
                }
                else if (panGesture.State == UIGestureRecognizerState.Ended)
                {
                    dx = 0;
                    dy = 0;
                }
            });

            imageView.AddGestureRecognizer(panGesture);
            imageView.AddGestureRecognizer(rotateGesture);

            View.BackgroundColor = UIColor.White;
        }
Example #16
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);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            ((MasterDetailPage)Element).PropertyChanged += HandlePropertyChanged;

            var model = (MasterDetailPage)Element;

            if (!model.IsGestureEnabled)
            {
                if (_panGesture != null)
                {
                    View.RemoveGestureRecognizer(_panGesture);
                }
                return;
            }

            if (_panGesture != null)
            {
                View.AddGestureRecognizer(_panGesture);
                return;
            }

            UITouchEventArgs shouldReceive = (g, t) => !(t.View is UISlider);
            var center = new PointF();

            _panGesture = new UIPanGestureRecognizer(g =>
            {
                var detailRenderer  = Platform.GetRenderer(((MasterDetailPage)Element).Detail);
                var masterRenderer  = Platform.GetRenderer(((MasterDetailPage)Element).Master);
                var translation     = g.TranslationInView(View).X;
                var presented       = ((MasterDetailPage)Element).IsPresented;
                double openProgress = 0;
                double openLimit    = masterRenderer.ViewController.View.Frame.Width;

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

                openProgress = Math.Min(Math.Max(openProgress, 0.0), 1.0);
                switch (g.State)
                {
                case UIGestureRecognizerState.Changed:
                    LayoutViews(View.Bounds, (nfloat)openProgress, detailRenderer.ViewController.View);
                    break;
                }
            })
            {
                ShouldReceiveTouch     = shouldReceive,
                MaximumNumberOfTouches = 2
            };
            _panGesture.ShouldRecognizeSimultaneously = (gesture1, gesture2) => true;
            View.AddGestureRecognizer(_panGesture);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var panGesture = new UIPanGestureRecognizer(HandlePan);

            this.View.AddGestureRecognizer(panGesture);
        }
Example #19
0
 private void Initialize()
 {
     ViewExpanded    = false;
     _menuPanGesture = new UIPanGestureRecognizer(SlideMenuFromPan);
     _menuTapGesture = new UITapGestureRecognizer(ShowOrHideMenuFromTap);
     AddGestureRecognizer(_menuTapGesture);
     AddGestureRecognizer(_menuPanGesture);
 }
Example #20
0
 public iOSPanEventArgs(UIPanGestureRecognizer gr, PanEventArgs previous, CoreGraphics.CGPoint locationAtStart)
 {
     Cancelled    = (gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed);
     ViewPosition = iOSEventArgsHelper.GetViewPosition(gr.View.Frame);
     Touches      = iOSEventArgsHelper.GetTouches(gr, locationAtStart);
     base.CalculateDistances(previous);
     Velocity = GetVelocity(gr);
 }
        public void RevealGesture(UIPanGestureRecognizer recognizer)
        {
            MenuViewController rearVC = (MenuViewController)SidebarViewController;

            rearVC.searchBar.ResignFirstResponder();

            base.DragContentView(recognizer);
        }
        /*
         * public override void TouchesBegan (NSSet touches, UIEvent e)
         * {
         *      base.TouchesBegan (touches, e);
         *
         *      UITouch touch = (UITouch)touches.AnyObject;
         *      PointF positionInScene = touch.LocationInNode (this);
         *      this.SelectNodeForTouch (positionInScene);
         * }
         *
         * public override void TouchesMoved(NSSet touches, UIEvent e)
         * {
         *      base.TouchesMoved (touches, e);
         *
         *      UITouch touch = (UITouch)touches.AnyObject;
         *      PointF positionInScene = touch.LocationInNode (this);
         *      PointF previousPosition = touch.PreviousLocationInNode (this);
         *
         *      PointF translation = new PointF (positionInScene.X - previousPosition.X, positionInScene.Y - previousPosition.Y);
         *      this.PanForTranslation (translation);
         * }
         */

        public override void DidMoveToView(SKView view)
        {
            base.DidMoveToView(view);

            UIPanGestureRecognizer gestureRecognizer = new UIPanGestureRecognizer(HandlePanFrom);

            this.View.AddGestureRecognizer(gestureRecognizer);
        }
Example #23
0
 private void onDrag(UIPanGestureRecognizer gesture)
 {
     if (shouldSkipGesture(gesture))
     {
         return;
     }
     fireEvent(OnUserDrag, gesture);
 }
Example #24
0
 public void WillDisapear()
 {
     if (panGesture != null)
     {
         NowPlaying.View.RemoveGestureRecognizer(panGesture);
         panGesture = null;
     }
 }
 protected void HandlePanGesture(UIPanGestureRecognizer gesture)
 {
     if (this.Animator.Running || this.PanGestureEvent == null)
     {
         return;
     }
     this.PanGestureEvent(gesture);
 }
 void OnProgressPan(UIPanGestureRecognizer recognizer)
 {
     if (ContainerView != null)
     {
         var point = recognizer.LocationInView(ContainerView);
         UpdateProgressBaseOnPoint(point);
     }
 }
Example #27
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            image.UserInteractionEnabled = true; //
            var GestoToque = new UITapGestureRecognizer(Tocando);

            //Se aplican los gestos a la imagen
            image.AddGestureRecognizer(GestoToque);

            GestoMover = new UIPanGestureRecognizer(() =>
            {
                if ((GestoMover.State == UIGestureRecognizerState.Began || //Validar el estado del gesto
                     GestoMover.State == UIGestureRecognizerState.Changed) &&
                    (GestoMover.NumberOfTouches == 1))
                {
                    var P0 = GestoMover.LocationInView(View); //Gesto en toda la pantalla.

                    if (coordenadasX == 0)
                    {
                        coordenadasX = P0.X - image.Center.X;
                    }

                    if (coordenadasY == 0)
                    {
                        coordenadasY = P0.Y - image.Center.Y;
                    }

                    var P1 = new CGPoint(P0.X - coordenadasX, P0.Y - coordenadasY);

                    image.Center = P1;
                }
                else
                {
                    coordenadasX = 0;
                    coordenadasY = 0;
                }
            });


            GestoRotar = new UIRotationGestureRecognizer(() =>
            {
                if ((GestoRotar.State == UIGestureRecognizerState.Began ||                            //Validar el estado del gesto
                     GestoRotar.State == UIGestureRecognizerState.Changed) &&
                    (GestoRotar.NumberOfTouches == 2))                                                //el gesto de rotar se hace con dos toques.
                {
                    image.Transform = CGAffineTransform.MakeRotation(GestoRotar.Rotation + rotacion); //Se vuelve a verificar el estado, para validar en donde se quedo.
                }
                else if (GestoRotar.State == UIGestureRecognizerState.Ended)
                {
                    rotacion = GestoRotar.Rotation; //Se obtinen los valores de rotación.
                }
            });

            //Se aplican los gestos a la imagen
            image.AddGestureRecognizer(GestoMover);
            image.AddGestureRecognizer(GestoRotar);
        }
        private void OnPanningGesture (UIPanGestureRecognizer gesture)
        {
            switch (gesture.State) {
            case UIGestureRecognizerState.Began:
                panStart = gesture.TranslationInView (actualContentView);
                panLockInHorizDirection = false;
                break;
            case UIGestureRecognizerState.Changed:
                var currentPoint = gesture.TranslationInView (actualContentView);
                panDeltaX = panStart.X - currentPoint.X;

                if (panDeltaX > 0) {
                    panDeltaX = 0;
                    return;
                }

                if (!panLockInHorizDirection) {
                    if (Math.Abs (panDeltaX) > 30) {
                        // User is swiping the cell, lock them into this direction
                        panLockInHorizDirection = true;
                    } else if (Math.Abs (panStart.Y - currentPoint.Y) > 5) {
                        // User is starting to move upwards, let them scroll
                        gesture.Enabled = false;
                    }
                }

                if (-SwipeWidth > panDeltaX) {
                    panDeltaX = -SwipeWidth;
                }

                UIView.AnimateNotify (0.1, 0, UIViewAnimationOptions.CurveEaseOut, LayoutActualContentView, null);
                break;
            case UIGestureRecognizerState.Ended:
                if (Editing) {
                    break;
                }

                if (!gesture.Enabled) {
                    gesture.Enabled = true;
                }

                var velocityX = gesture.VelocityInView (gesture.View).X;
                var absolutePanDeltaX = Math.Abs (panDeltaX);
                var duration = Math.Max (MinDuration, Math.Min (MaxDuration, (absolutePanDeltaX) / velocityX));

                UIView.AnimateNotify (duration, () => LayoutActualContentView (0), isFinished => {
                    if (isFinished && absolutePanDeltaX > SwipeWidth - 5) {
                        OnContinueGestureFinished ();
                    }
                });

                break;
            case UIGestureRecognizerState.Cancelled:
                UIView.AnimateNotify (0.3, () => LayoutActualContentView (0), isFinished => gesture.Enabled = isFinished);
                break;
            }

        }
Example #29
0
        public DraggableView()
        {
            _panGestureRecognizer = new UIPanGestureRecognizer(HandleOnGestureRecognizer);

            RotationStrength          = 300;
            RotationAnimationDuration = 0.85f;
            ScaleStrength             = 0.85f;
            SwipeThreshold            = 140;
        }
Example #30
0
        private void AddPanGestureToView(UIView view)
        {
            var panGesture = new UIPanGestureRecognizer(this.HandlePan);

            panGesture.Delegate = this;
            panGesture.MaximumNumberOfTouches = 1;
            panGesture.MinimumNumberOfTouches = 1;
            view.AddGestureRecognizer(panGesture);
        }
Example #31
0
        /**
         * Adds a pan edge gesture to a view to present menus.
         *
         * - Parameter toView: The view to add a pan gesture to.
         *
         * - Returns: The pan gesture added to `toView`.
         */
        public UIPanGestureRecognizer AddPanGestureToPresent(UIView toView)
        {
            var panGestureRecognizer = new UIPanGestureRecognizer();

            panGestureRecognizer.AddTarget(/*SideMenuTransition.self, */ () => SideMenuTransition.HandlePresentMenuPan(panGestureRecognizer));
            toView.AddGestureRecognizer(panGestureRecognizer);

            return(panGestureRecognizer);
        }
 protected void WireUpDragGestureRecognizer()
 {
     // create a new tap gesture
     UIPanGestureRecognizer gesture = new UIPanGestureRecognizer();
     // wire up the event handler (have to use a selector)
     gesture.AddTarget(() => HandleDrag(gesture));
     // add the gesture recognizer to the view
     imgDragMe.AddGestureRecognizer(gesture);
 }
Example #33
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            var gesture = new UIPanGestureRecognizer((g) => PanGesture(g));

            View.AddGestureRecognizer(gesture);
        }
        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 HandleDrag(UIPanGestureRecognizer gesture)
        {
            if (_isSearchActive)
            {
                _search.SearchBar.ResignFirstResponder();
            }

            _tableViews[_currentPageViewIndex].RemoveGestureRecognizer(gesture);
        }
Example #36
0
 public void CreatePangesture()
 {
     if (panRecognizer == null)
     {
         panRecognizer          = new UIPanGestureRecognizer(PanThisCell);
         panRecognizer.Delegate = this;
         vMyContent.AddGestureRecognizer(panRecognizer);
     }
 }
 private void HandleDrag(UIPanGestureRecognizer gesture)
 {
     if (!_dismissing)
     {
         this.View.RemoveGestureRecognizer(gesture);
         Dismiss();
         _openChatAction.Invoke(false);
     }
 }
Example #38
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();
            var tapGestureRecognizer  = new UITapGestureRecognizer(Tap);
            var panGestureRecogrnizer = new UIPanGestureRecognizer(Pan);

            AddGestureRecognizer(tapGestureRecognizer);
            AddGestureRecognizer(panGestureRecogrnizer);
        }
		public DraggableView () 
		{ 
			_panGestureRecognizer = new UIPanGestureRecognizer (HandleOnGestureRecognizer);

			RotationStrength = 300;
			RotationAnimationDuration = 0.85f;
			ScaleStrength = 0.85f;
			SwipeThreshold = 140;
		}
        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);
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <Frame> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement == null)
            {
                RemoveGestureRecognizer();

                return;
            }

            var gestureView = e.NewElement as GestureAwareContentView;

            _longPressGestureRecognizer = new UILongPressGestureRecognizer(
                sender => {
                var offset = sender.LocationInView(NativeView);

                GestureUtil.ExecuteCommand(gestureView.LongPress,
                                           new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y));
            });

            _pinchGestureRecognizer = new UIPinchGestureRecognizer(
                sender => {
                var scale = sender.Scale;

                GestureUtil.ExecuteCommand(gestureView.Pinch,
                                           new GestureScale(sender.State.ToGestureState(), scale));
            });

            _panGestureRecognizer = new UIPanGestureRecognizer(
                sender => {
                var offset = sender.TranslationInView(NativeView);

                GestureUtil.ExecuteCommand(gestureView.Pan,
                                           new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y));
            });

            _swipeGestureRecognizer = new UISwipeGestureRecognizer(
                sender => {
                var offset = sender.LocationInView(NativeView);

                GestureUtil.ExecuteCommand(gestureView.Swipe,
                                           new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y));
            });

            _rotationGestureRecognizer = new UIRotationGestureRecognizer(
                sender => {
                GestureUtil.ExecuteCommand(gestureView.Rotate);
            });

            AddGestureRecognizer(_longPressGestureRecognizer);
            AddGestureRecognizer(_pinchGestureRecognizer);
            AddGestureRecognizer(_panGestureRecognizer);
            AddGestureRecognizer(_swipeGestureRecognizer);
            AddGestureRecognizer(_rotationGestureRecognizer);
        }
        public override void LoadView()
        {
            base.LoadView();
            window = AppDelegate.TogglWindow;
            View.BackgroundColor = UIColor.White;

            _panGesture = new UIPanGestureRecognizer(OnPanGesture)
            {
                CancelsTouchesInView = true
            };

            menuButtons = new[] {
                (logButton = new UIButton()),
                (reportsButton = new UIButton()),
                (settingsButton = new UIButton()),
                (feedbackButton = new UIButton()),
                (signOutButton = new UIButton()),
            };
            logButton.SetTitle("LeftPanelMenuLog".Tr(), UIControlState.Normal);
            logButton.SetImage(Image.TimerButton, UIControlState.Normal);
            logButton.SetImage(Image.TimerButtonPressed, UIControlState.Highlighted);

            reportsButton.SetTitle("LeftPanelMenuReports".Tr(), UIControlState.Normal);
            reportsButton.SetImage(Image.ReportsButton, UIControlState.Normal);
            reportsButton.SetImage(Image.ReportsButtonPressed, UIControlState.Highlighted);

            settingsButton.SetTitle("LeftPanelMenuSettings".Tr(), UIControlState.Normal);
            settingsButton.SetImage(Image.SettingsButton, UIControlState.Normal);
            settingsButton.SetImage(Image.SettingsButtonPressed, UIControlState.Highlighted);

            feedbackButton.SetTitle("LeftPanelMenuFeedback".Tr(), UIControlState.Normal);
            feedbackButton.SetImage(Image.FeedbackButton, UIControlState.Normal);
            feedbackButton.SetImage(Image.FeedbackButtonPressed, UIControlState.Highlighted);

            signOutButton.SetTitle("LeftPanelMenuSignOut".Tr(), UIControlState.Normal);
            signOutButton.SetImage(Image.SignoutButton, UIControlState.Normal);
            signOutButton.SetImage(Image.SignoutButtonPressed, UIControlState.Highlighted);

            logButton.HorizontalAlignment          = reportsButton.HorizontalAlignment = settingsButton.HorizontalAlignment =
                feedbackButton.HorizontalAlignment = signOutButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;

            var authManager = ServiceContainer.Resolve <AuthManager> ();

            authManager.PropertyChanged += OnUserLoad;

            foreach (var button in menuButtons)
            {
                button.Apply(Style.LeftView.Button);
                button.TouchUpInside += OnMenuButtonTouchUpInside;
                View.AddSubview(button);
            }

            View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
            View.AddConstraints(MakeConstraints(View));
            View.AddGestureRecognizer(_panGesture);
        }
        protected void WireUpDragGestureRecognizer()
        {
            //---- create a new tap gesture
            UIPanGestureRecognizer gesture = new UIPanGestureRecognizer();

            //---- wire up the event handler (have to use a selector)
            gesture.AddTarget(this, new Selector("HandleDrag"));
            //---- add the gesture recognizer to the view
            this.imgDragMe.AddGestureRecognizer(gesture);
        }
        protected void WireUpDragGestureRecognizer()
        {
            // create a new tap gesture
            UIPanGestureRecognizer gesture = new UIPanGestureRecognizer();

            // wire up the event handler (have to use a selector)
            gesture.AddTarget(() => { HandleDrag(gesture); });
            // add the gesture recognizer to the view
            imgDragMe.AddGestureRecognizer(gesture);
        }
Example #45
0
        UIPanGestureRecognizer CreatePanRecognizer(int numTouches, Action <UIPanGestureRecognizer> action)
        {
            var result = new UIPanGestureRecognizer(action);

            result.MinimumNumberOfTouches = result.MaximumNumberOfTouches = (uint)numTouches;

            // enable touches to pass through so that underlying scrolling views will still receive the pan
            result.ShouldRecognizeSimultaneously = (g, o) => Application.Current?.OnThisPlatform().GetPanGestureRecognizerShouldRecognizeSimultaneously() ?? false;
            return(result);
        }
Example #46
0
        public iOSPanEventArgs(UIPanGestureRecognizer gr, BaseGestureEventArgs previous)
        {
            Cancelled       = (gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed);
            ElementPosition = gr.View.BoundsInFormsCoord();
            ElementTouches  = iOSEventArgsHelper.GetTouches(gr, gr.View);
            WindowTouches   = iOSEventArgsHelper.GetTouches(gr, null);

            CalculateDistances(previous);
            Velocity = GetVelocity(gr);
        }
        protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
        {
            base.OnElementChanged (e);

            if (e.NewElement == null) {
                RemoveGestureRecognizer ();

                return;
            }

            var gestureView = e.NewElement as GestureAwareContentView;

            _longPressGestureRecognizer = new UILongPressGestureRecognizer (
                sender => {
                    var offset = sender.LocationInView(NativeView);

                    GestureUtil.ExecuteCommand(gestureView.LongPress,
                        new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y));
                });

            _pinchGestureRecognizer = new UIPinchGestureRecognizer (
                sender => {
                    var scale = sender.Scale;

                    GestureUtil.ExecuteCommand(gestureView.Pinch,
                        new GestureScale(sender.State.ToGestureState(), scale));
                });

            _panGestureRecognizer = new UIPanGestureRecognizer (
                sender => {
                    var offset = sender.TranslationInView(NativeView);

                    GestureUtil.ExecuteCommand(gestureView.Pan,
                        new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y));
                });

            _swipeGestureRecognizer = new UISwipeGestureRecognizer (
                sender => {
                    var offset = sender.LocationInView(NativeView);

                    GestureUtil.ExecuteCommand(gestureView.Swipe,
                        new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y));
                });

            _rotationGestureRecognizer = new UIRotationGestureRecognizer (
                sender => {
                    GestureUtil.ExecuteCommand (gestureView.Rotate);
                });

            AddGestureRecognizer (_longPressGestureRecognizer);
            AddGestureRecognizer (_pinchGestureRecognizer);
            AddGestureRecognizer (_panGestureRecognizer);
            AddGestureRecognizer (_swipeGestureRecognizer);
            AddGestureRecognizer (_rotationGestureRecognizer);
        }
		private void WireUpDragGestureRecognizer()
		{
			// Create a new tap gesture
			UIPanGestureRecognizer gesture = new UIPanGestureRecognizer();

			// Wire up the event handler (have to use a selector)
			gesture.AddTarget(() => HandleDrag(gesture));

			// Add the gesture recognizer to the view
			DragImage.AddGestureRecognizer(gesture);
		}
        public BezierSignatureView(RectangleF frame, bool isSigning = true)
            : base(frame)
        {
            IsSigning = isSigning;
            _drawPath = new CGPath ();
            BackgroundColor = UIColor.White;
            MultipleTouchEnabled = false;

            _panner = new UIPanGestureRecognizer (this, new MonoTouch.ObjCRuntime.Selector("BezierSignatureViewPan"));
            _panner.MaximumNumberOfTouches = _panner.MinimumNumberOfTouches = 1;
            AddGestureRecognizer (_panner);
        }
        public override void LoadView ()
        {
            base.LoadView ();
            window = AppDelegate.TogglWindow;
            View.BackgroundColor = UIColor.White;

            _panGesture = new UIPanGestureRecognizer (OnPanGesture) {
                CancelsTouchesInView = true
            };

            menuButtons = new[] {
                (logButton = new UIButton ()),
                (reportsButton = new UIButton ()),
                (settingsButton = new UIButton ()),
                (feedbackButton = new UIButton ()),
                (signOutButton = new UIButton ()),
            };
            logButton.SetTitle ("LeftPanelMenuLog".Tr (), UIControlState.Normal);
            logButton.SetImage (Image.TimerButton, UIControlState.Normal);
            logButton.SetImage (Image.TimerButtonPressed, UIControlState.Highlighted);

            reportsButton.SetTitle ("LeftPanelMenuReports".Tr (), UIControlState.Normal);
            reportsButton.SetImage (Image.ReportsButton, UIControlState.Normal);
            reportsButton.SetImage (Image.ReportsButtonPressed, UIControlState.Highlighted);

            settingsButton.SetTitle ("LeftPanelMenuSettings".Tr (), UIControlState.Normal);
            settingsButton.SetImage (Image.SettingsButton, UIControlState.Normal);
            settingsButton.SetImage (Image.SettingsButtonPressed, UIControlState.Highlighted);

            feedbackButton.SetTitle ("LeftPanelMenuFeedback".Tr (), UIControlState.Normal);
            feedbackButton.SetImage (Image.FeedbackButton, UIControlState.Normal);
            feedbackButton.SetImage (Image.FeedbackButtonPressed, UIControlState.Highlighted);

            signOutButton.SetTitle ("LeftPanelMenuSignOut".Tr (), UIControlState.Normal);
            signOutButton.SetImage (Image.SignoutButton, UIControlState.Normal);
            signOutButton.SetImage (Image.SignoutButtonPressed, UIControlState.Highlighted);

            logButton.HorizontalAlignment = reportsButton.HorizontalAlignment = settingsButton.HorizontalAlignment =
                                                feedbackButton.HorizontalAlignment = signOutButton.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;

            var authManager = ServiceContainer.Resolve<AuthManager> ();
            authManager.PropertyChanged += OnUserLoad;

            foreach (var button in menuButtons) {
                button.Apply (Style.LeftView.Button);
                button.TouchUpInside += OnMenuButtonTouchUpInside;
                View.AddSubview (button);
            }

            View.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
            View.AddConstraints (MakeConstraints (View));
            View.AddGestureRecognizer (_panGesture);
        }
        public PlayGroundView()
        {
            pinchGesture = new UIPinchGestureRecognizer (Scale);
            this.AddGestureRecognizer (pinchGesture);

            var rotationGesture = new UIRotationGestureRecognizer (Rotate);
            this.AddGestureRecognizer (rotationGesture);

            var panGesture = new UIPanGestureRecognizer (Move);
            this.AddGestureRecognizer (panGesture);

            this.BackgroundColor = UIColor.DarkGray;
        }
		void Pan (UIPanGestureRecognizer pan)
		{
			var location = pan.LocationInView (View);

			switch (pan.State) {
			case UIGestureRecognizerState.Began:
				// Capture the initial touch offset from the itemView's center.
				var center = itemView.Center;
				offset.X = location.X - center.X;
				offset.Y = location.Y - center.Y;

				// Disable the behavior while the item is manipulated by the pan recognizer.
				stickyBehavior.Enabled = false;
				break;
			case UIGestureRecognizerState.Changed:
				// Get reference bounds.
				var referenceBounds = View.Bounds;
				var referenceWidth = referenceBounds.Width;
				var referenceHeight = referenceBounds.Height;

				// Get item bounds.
				var itemBounds = itemView.Bounds;
				var itemHalfWidth = itemBounds.Width / 2f;
				var itemHalfHeight = itemBounds.Height / 2f;

				// Apply the initial offset.
				location.X -= offset.X;
				location.Y -= offset.Y;

				// Bound the item position inside the reference view.
				location.X = NMath.Max (itemHalfWidth, location.X);
				location.X = NMath.Min (referenceWidth - itemHalfWidth, location.X);
				location.Y = NMath.Max (itemHalfHeight, location.Y);
				location.Y = NMath.Min (referenceHeight - itemHalfHeight, location.Y);

				// Apply the resulting item center.
				itemView.Center = location;
				break;
			case UIGestureRecognizerState.Ended:
			case UIGestureRecognizerState.Cancelled:
				// Get the current velocity of the item from the pan gesture recognizer.
				var velocity = pan.VelocityInView (View);

				// Re-enable the stickyCornersBehavior.
				stickyBehavior.Enabled = true;

				// Add the current velocity to the sticky corners behavior.
				stickyBehavior.AddLinearVelocity (velocity);
				break;
			}
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			
			nfloat r = 0;
			nfloat dx = 0;
			nfloat dy = 0;
			
			using (var image = UIImage.FromFile ("monkey.png")) {
				imageView = new UIImageView (image){Frame = new CGRect (new CGPoint(0,0), image.Size)};
				imageView.UserInteractionEnabled = true;
				View.AddSubview (imageView);
			}
			rotateGesture = new UIRotationGestureRecognizer ((() => {
				if ((rotateGesture.State == UIGestureRecognizerState.Began || rotateGesture.State == UIGestureRecognizerState.Changed) && (rotateGesture.NumberOfTouches == 2)) {

					imageView.Transform = CGAffineTransform.MakeRotation (rotateGesture.Rotation + r);
				} else if (rotateGesture.State == UIGestureRecognizerState.Ended) {
					r += rotateGesture.Rotation;
				}
			}));

			
			panGesture = new UIPanGestureRecognizer (() => {
				if ((panGesture.State == UIGestureRecognizerState.Began || panGesture.State == UIGestureRecognizerState.Changed) && (panGesture.NumberOfTouches == 1)) {
					
					var p0 = panGesture.LocationInView (View);
					
					if (dx == 0)
						dx = p0.X - imageView.Center.X;
					
					if (dy == 0)
						dy = p0.Y - imageView.Center.Y;
					
					var p1 = new CGPoint (p0.X - dx, p0.Y - dy);
					
					imageView.Center = p1;
				} else if (panGesture.State == UIGestureRecognizerState.Ended) {
					dx = 0;
					dy = 0;
				}
			});
			
			imageView.AddGestureRecognizer (panGesture);
			imageView.AddGestureRecognizer (rotateGesture);
			
			View.BackgroundColor = UIColor.White;
		}
        protected void HandleDrag(UIPanGestureRecognizer recognizer)
        {
            // if it's just began, cache the location of the image
            if (recognizer.State == UIGestureRecognizerState.Began)
                originalImageFrame = imgDragMe.Frame;

            if (recognizer.State != (UIGestureRecognizerState.Cancelled | UIGestureRecognizerState.Failed
                | UIGestureRecognizerState.Possible)) {

                // move the shape by adding the offset to the object's frame
                System.Drawing.PointF offset = recognizer.TranslationInView (imgDragMe);
                System.Drawing.RectangleF newFrame = originalImageFrame;
                newFrame.Offset (offset.X, offset.Y);
                imgDragMe.Frame = newFrame;
            }
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			imageView.Image = UIImage.FromFile ("*****@*****.**");

			if (model != null)
				textView.AttributedText = model.GetAttributedText ();

			textView.TextAlignment = UITextAlignment.Justified;
			textView.TextContainer.ExclusionPaths = TranslatedBezierPath ();

			UIPanGestureRecognizer gesture = new UIPanGestureRecognizer (HandlePanGesture);

			imageView.UserInteractionEnabled = true;
			imageView.AddGestureRecognizer (gesture);
		}
        public void HandleGesture(UIPanGestureRecognizer panGestureRecognizer)
        {
            PointF translation = panGestureRecognizer.TranslationInView (panGestureRecognizer.View.Superview);

            switch (gestureRecognizer.State) {
            case UIGestureRecognizerState.Began:
                TrackGestureBegan (translation);
                break;
            case UIGestureRecognizerState.Changed:
                TrackGestureChaged (translation);
                break;
            case UIGestureRecognizerState.Ended:
            case UIGestureRecognizerState.Cancelled:
                TrackGestureEnded (panGestureRecognizer.State);
                break;
            }
        }
		private void HandleDrag(UIPanGestureRecognizer recognizer)
		{
			// If it's just began, cache the location of the image
			if (recognizer.State == UIGestureRecognizerState.Began)
			{
				originalImageFrame = DragImage.Frame;
			}

			// Move the image if the gesture is valid
			if (recognizer.State != (UIGestureRecognizerState.Cancelled | UIGestureRecognizerState.Failed
				| UIGestureRecognizerState.Possible))
			{
				// Move the image by adding the offset to the object's frame
				CGPoint offset = recognizer.TranslationInView(DragImage);
				CGRect newFrame = originalImageFrame;
				newFrame.Offset(offset.X, offset.Y);
				DragImage.Frame = newFrame;
			}
		}
        //TODO: Step 11b - Provide the handler drag event
        private void HandleDrag(UIPanGestureRecognizer recognizer)
        {
            switch (recognizer.State)
            {
                case UIGestureRecognizerState.Began:
                    // if it's just began, cache the location of the image
                    originalImageFrame = imgDragMe.Frame;
                    break;

                case UIGestureRecognizerState.Possible:
                case UIGestureRecognizerState.Cancelled:
                case UIGestureRecognizerState.Failed:
                    return;
            }

            // move the shape by adding the offset to the object's frame
            PointF offset = recognizer.TranslationInView(imgDragMe);
            var newFrame = originalImageFrame;
            newFrame.Offset(offset.X, offset.Y);
            imgDragMe.Frame = newFrame;
        }
Example #59
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.Black;
            _wallpaperView = new UIImageView(View.Bounds);
            _wallpaperView.Image = UIImage.FromBundle("Wallpaper");
            _wallpaperView.ContentMode = UIViewContentMode.ScaleAspectFill;
            View.AddSubview(_wallpaperView);

            RectangleF valueFrame = View.Bounds;
            valueFrame.Height = valueFrame.Height * 0.25f;
            _valueLabel = new UILabel(valueFrame);
            _valueLabel.Font = UIFont.FromName("HelveticaNeue-UltraLight", 32.0f);
            _valueLabel.TextColor = UIColor.White;
            _valueLabel.TextAlignment = UITextAlignment.Center;
            _valueLabel.Lines = 0;
            _valueLabel.Alpha = 0.0f;
            _valueLabel.BackgroundColor = UIColor.Clear;
            View.AddSubview(_valueLabel);

            _shimmeringView = new ShimmeringView();
            _shimmeringView.Shimmering = true;
            _shimmeringView.ShimmeringBeginFadeDuration = 0.3;
            _shimmeringView.ShimmeringOpacity = 0.3f;
            View.AddSubview(_shimmeringView);

            _logoLabel = new UILabel(_shimmeringView.Bounds);
            _logoLabel.Text = "Shimmer";
            _logoLabel.Font = UIFont.FromName("HelveticaNeue-UltraLight", 60.0f);
            _logoLabel.TextColor = UIColor.White;
            _logoLabel.TextAlignment = UITextAlignment.Center;
            _logoLabel.BackgroundColor = UIColor.Clear;
            _shimmeringView.AddSubview(_logoLabel);

            UITapGestureRecognizer tapRecognizer = new UITapGestureRecognizer(OnTapped);
            View.AddGestureRecognizer(tapRecognizer);
            UIPanGestureRecognizer panRecognizer = new UIPanGestureRecognizer(OnPanned);
            View.AddGestureRecognizer(panRecognizer);
        }
        public void HandleGesture(UIPanGestureRecognizer gestureRecognizer)
        {
            CGPoint translation = gestureRecognizer.TranslationInView (gestureRecognizer.View.Superview);

            switch (gestureRecognizer.State) {
            case UIGestureRecognizerState.Began:
                bool topToBottomSwipe = translation.Y > 0f;
                if (operation == CEInteractionOperation.Pop) {
                    if (topToBottomSwipe) {
                        InteractionInProgress = true;
                        viewController.NavigationController.PopViewController (true);
                    }
                } else {
                    InteractionInProgress = true;
                    viewController.DismissViewController (true, null);
                }
                break;
            case UIGestureRecognizerState.Changed:
                if (InteractionInProgress) {
                    // compute the current position
                    float fraction = (float)translation.Y / 200f;
                    fraction = Math.Min (Math.Max (fraction, 0f), 1f);
                    shouldCompleteTransition = (fraction > 0.5f);

                    UpdateInteractiveTransition (fraction);
                }
                break;
            case UIGestureRecognizerState.Ended:
            case UIGestureRecognizerState.Cancelled:
                if (InteractionInProgress) {
                    InteractionInProgress = false;
                    if (!shouldCompleteTransition || gestureRecognizer.State == UIGestureRecognizerState.Cancelled) {
                        CancelInteractiveTransition ();
                    } else {
                        FinishInteractiveTransition ();
                    }
                }
                break;
            }
        }