コード例 #1
0
        void OnUp(DownUpGestureRecognizer gr, UITouch[] touchesEnded)
        {
            if (!_element.IsVisible)
            {
                return;
            }

            bool            handled = false;
            DownUpEventArgs args    = new iOSDownUpEventArgs(gr, touchesEnded);

            foreach (var listener in _listeners)
            {
                if (listener.HandlesUp)
                {
                    args.Listener = listener;
                    listener.OnUp(args);
                    handled = handled || args.Handled;
                    if (handled)
                    {
                        break;
                    }
                }
            }
            touchCount--;
        }
コード例 #2
0
 public iOSDownUpEventArgs(DownUpGestureRecognizer gr, UITouch[] triggeringTouches, CoreGraphics.CGPoint viewLocationAtStart)
 {
     Cancelled         = (gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed);
     ViewPosition      = iOSEventArgsHelper.GetViewPosition(gr.View.Frame);
     Touches           = iOSEventArgsHelper.GetTouches(gr, viewLocationAtStart);
     TriggeringTouches = GetTriggeringTouches(gr, triggeringTouches, viewLocationAtStart);
 }
コード例 #3
0
        void OnDown(DownUpGestureRecognizer gr, UITouch[] touchesBegan)
        {
            _panning = false;
            if (!_element.IsVisible)
            {
                return;
            }

            bool handled = false;

            touchCount++;
            DownUpEventArgs args = new iOSDownUpEventArgs(gr, touchesBegan);

            foreach (var listener in _listeners)
            {
                if (listener.HandlesDown)
                {
                    args.Listener = listener;
                    listener.OnDown(args);
                    handled = handled || args.Handled;
                    if (handled)
                    {
                        break;
                    }
                }
            }
            _downGestureArgs = args;
        }
コード例 #4
0
 public iOSDownUpEventArgs(DownUpGestureRecognizer gr, UITouch[] triggeringTouches)
 {
     Cancelled         = (gr.State == UIGestureRecognizerState.Cancelled || gr.State == UIGestureRecognizerState.Failed);
     ElementPosition   = gr.View.BoundsInFormsCoord();
     ElementTouches    = iOSEventArgsHelper.GetTouches(gr, gr.View);
     WindowTouches     = iOSEventArgsHelper.GetTouches(gr, null);
     TriggeringTouches = GetTriggeringTouches(gr, triggeringTouches);
 }
コード例 #5
0
        private int[] GetTriggeringTouches(DownUpGestureRecognizer gr, UITouch[] triggeringTouches, CoreGraphics.CGPoint locationAtStart)
        {
            Point[] array = Enumerable.ToArray <Point>(Enumerable.Select <UITouch, Point>(triggeringTouches, delegate(UITouch t) {
                CGPoint cGPoint = t.LocationInView(null);
                return(new Point(cGPoint.X - locationAtStart.X, cGPoint.Y - locationAtStart.Y));
            }));
            List <int> list = new List <int>();

            for (int i = 0; i < Touches.Length; i++)
            {
                Point t = Touches[i];
                if (Enumerable.Any <Point>(array, (Point p) => Math.Abs(p.X - t.X) < 0.1 && Math.Abs(p.Y - t.Y) < 0.1))
                {
                    list.Add(i);
                }
            }
            return(list.ToArray());
        }
コード例 #6
0
        void OnDown(DownUpGestureRecognizer gr, UITouch[] touchesBegan)
        {
            _panning = false;
            if (!_element.IsVisible)
            {
                return;
            }

            /*
             *          var control = (UIView)_view.GetPropertyValue ("Control");
             *          if (control is UIButton)
             *                  ((UIButton)control).SendActionForControlEvents (UIControlEvent.TouchDown);
             */
            bool handled = false;

            if (touchCount == 0)
            {
                //System.Diagnostics.Debug.WriteLine("onDown set _viewLocationAtOnDown");
                _viewLocationAtOnDown = ViewLocationInWindow(gr.View);
            }
            touchCount++;
            //System.Diagnostics.Debug.WriteLine("\tNativeGestureHandler.onDown _touchCount=["+_touchCount+"] _viewLocation=["+_viewLocationAtOnDown+"]");
            foreach (var listener in _listeners)
            {
                //if (handled)
                //	break;
                if (listener.HandlesDown)
                {
                    DownUpEventArgs args = new iOSDownUpEventArgs(gr, touchesBegan, _viewLocationAtOnDown)
                    {
                        Listener = listener
                    };
                    listener.OnDown(args);
                    handled = handled || args.Handled;
                    if (handled)
                    {
                        break;
                    }
                }
            }
            //gr.CancelsTouchesInView = handled;
            //System.Diagnostics.Debug.WriteLine("\thandled=["+handled+"]");
        }
コード例 #7
0
        void OnUp(DownUpGestureRecognizer gr, UITouch[] touchesEnded)
        {
            if (!_element.IsVisible)
            {
                return;
            }

            /*
             *          var control = (UIView)_view.GetPropertyValue ("Control");
             *          if (control is UIButton)
             *                  ((UIButton)control).SendActionForControlEvents (UIControlEvent.TouchUpInside);
             */
            bool handled = false;

            foreach (var listener in _listeners)
            {
                //if (handled)
                //	break;
                if (listener.HandlesUp)
                {
                    DownUpEventArgs args = new iOSDownUpEventArgs(gr, touchesEnded, _viewLocationAtOnDown)
                    {
                        Listener = listener
                    };
                    listener.OnUp(args);
                    handled = handled || args.Handled;
                    if (handled)
                    {
                        break;
                    }
                }
            }
            touchCount--;
            //System.Diagnostics.Debug.WriteLine("onUp touchCount-- = ["+_touchCount+"] touchesEnded.Length=["+touchesEnded.Length+"]");
            //System.Diagnostics.Debug.WriteLine("\tNativeGestureHandler.onUp _touchCount=[" + _touchCount + "] _viewLocation=[" + _viewLocationAtOnDown + "]");
            //gr.CancelsTouchesInView = handled;
            //System.Diagnostics.Debug.WriteLine("\thandled=[" + handled + "]");
        }
コード例 #8
0
#pragma warning disable IDE0060 // Remove unused parameter
        private int[] GetTriggeringTouches(DownUpGestureRecognizer gr, UITouch[] triggeringTouches)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            /*  remember this notation next time I trip over using blocks for expressions
             * Point[] array = triggeringTouches.Select(delegate(UITouch t) {
             *      CGPoint cGPoint = t.LocationInView(null);
             *      return cGPoint.ToPoint();
             * }).ToArray();
             */
            var array = triggeringTouches.Select(t => t.LocationInView(null).ToPoint()).ToArray();

            List <int> list = new List <int>();

            for (int i = 0; i < WindowTouches.Length; i++)
            {
                Point t = WindowTouches[i];
                if (array.Any(p => Math.Abs(p.X - t.X) < 0.1 && Math.Abs(p.Y - t.Y) < 0.1))
                {
                    list.Add(i);
                }
            }
            return(list.ToArray());
        }
コード例 #9
0
        UIGestureRecognizer[] CreateGestureRecognizers()
        {
            var list = new List <UIGestureRecognizer>();
            //if (HandlesDownUps)  WE NEED TO ALWAYS MONITOR FOR DOWN TO BE ABLE TO UNDO A CANCEL
            {  // commenting out if (HanglesDownUps) causes FormsDragNDrop listview to not recognize cell selections after a scroll.  Why?  I have no clue.
               // Let's always trigger the down gesture recognizer so we can get the starting location
                var downUpGestureRecognizer = new DownUpGestureRecognizer(new Action <DownUpGestureRecognizer, UITouch[]>(OnDown), new Action <DownUpGestureRecognizer, UITouch[]>(OnUp))
                {
                    ShouldRecognizeSimultaneously = ((thisGr, otherGr) => false),
                    ShouldReceiveTouch            = ((UIGestureRecognizer gr, UITouch touch) => !(touch.View is UIControl))
                };
                list.Add(downUpGestureRecognizer);
            }
            UILongPressGestureRecognizer uILongPressGestureRecognizer = null;

            if (HandlesLongs)
            {
                uILongPressGestureRecognizer = new UILongPressGestureRecognizer(new Action <UILongPressGestureRecognizer>(OnLongPressed))
                {
                    ShouldRecognizeSimultaneously = ((thisGr, otherGr) => false)
                };
                list.Add(uILongPressGestureRecognizer);
            }
            if (HandlesTaps)
            {
                var uITapGestureRecognizer = new UITapGestureRecognizer(new Action <UITapGestureRecognizer>(OnTapped))
                {
                    ShouldRecognizeSimultaneously = ((thisGr, otherGr) =>
                    {
                        return(thisGr.GetType() != otherGr.GetType());
                    }),
                    ShouldReceiveTouch = ((UIGestureRecognizer gr, UITouch touch) =>
                    {
                        // these are handled BEFORE the touch call is passed to the listener.
                        return(!(touch.View is UIControl));
                    })
                };
                if (uILongPressGestureRecognizer != null)
                {
                    uITapGestureRecognizer.RequireGestureRecognizerToFail(uILongPressGestureRecognizer);
                }
                list.Add(uITapGestureRecognizer);
            }
            if (HandlesPans)
            {
                var uIPanGestureRecognizer = new UIPanGestureRecognizer(new Action <UIPanGestureRecognizer>(OnPanned))
                {
                    MinimumNumberOfTouches        = 1,
                    ShouldRecognizeSimultaneously = ((thisGr, otherGr) => true)
                };
                list.Add(uIPanGestureRecognizer);
            }
            if (HandlesPinches)
            {
                var uIPinchGestureRecognizer = new UIPinchGestureRecognizer(new Action <UIPinchGestureRecognizer>(OnPinched))
                {
                    ShouldRecognizeSimultaneously = ((thisGr, otherGr) => true)
                };
                list.Add(uIPinchGestureRecognizer);
            }
            if (HandlesRotates)
            {
                var uIRotationGestureRecognizer = new UIRotationGestureRecognizer(new Action <UIRotationGestureRecognizer>(OnRotated))
                {
                    ShouldRecognizeSimultaneously = ((thisGr, otherGr) => true)
                };
                list.Add(uIRotationGestureRecognizer);
            }
            return(list.ToArray());
        }
コード例 #10
0
        UIGestureRecognizer[] CreateGestureRecognizers()
        {
            var list = new List <UIGestureRecognizer>();
            //if (HandlesDownUps)  WE NEED TO ALWAYS MONITOR FOR DOWN TO BE ABLE TO UNDO A CANCEL
            {  // commenting out if (HanglesDownUps) causes FormsDragNDrop listview to not recognize cell selections after a scroll.  Why?  I have no clue.
               // Let's always trigger the down gesture recognizer so we can get the starting location
                var downUpGestureRecognizer = new DownUpGestureRecognizer(new Action <DownUpGestureRecognizer, UITouch[]>(OnDown), new Action <DownUpGestureRecognizer, UITouch[]>(OnUp));
                downUpGestureRecognizer.ShouldRecognizeSimultaneously = ((thisGr, otherGr) => false);
                downUpGestureRecognizer.ShouldReceiveTouch            = ((UIGestureRecognizer gr, UITouch touch) => !(touch.View is UIControl));
                list.Add(downUpGestureRecognizer);
                //downUpGestureRecognizer.ShouldReceiveTouch = (recognizer, touch) => {
                //	return _element.get_IgnoreChildrenTouches() ? touch.View==_view : true;
                //};
            }
            UILongPressGestureRecognizer uILongPressGestureRecognizer = null;

            if (HandlesLongs)
            {
                uILongPressGestureRecognizer = new UILongPressGestureRecognizer(new Action <UILongPressGestureRecognizer>(OnLongPressed));
                uILongPressGestureRecognizer.ShouldRecognizeSimultaneously = ((thisGr, otherGr) => false);
                list.Add(uILongPressGestureRecognizer);
                //uILongPressGestureRecognizer.ShouldReceiveTouch = (recognizer, touch) => {
                //	return _element.get_IgnoreChildrenTouches() ? touch.View==_view : true;
                //};
            }
            if (HandlesTaps)
            {
                var uITapGestureRecognizer = new UITapGestureRecognizer(new Action <UITapGestureRecognizer>(OnTapped));
                uITapGestureRecognizer.ShouldRecognizeSimultaneously = ((thisGr, otherGr) =>
                {
                    return(thisGr.GetType() != otherGr.GetType());
                });
                uITapGestureRecognizer.ShouldReceiveTouch = ((UIGestureRecognizer gr, UITouch touch) =>
                {
                    // these are handled BEFORE the touch call is passed to the listener.
                    return(!(touch.View is UIControl));
                    //return touch.View == gr.View;
                });
                if (uILongPressGestureRecognizer != null)
                {
                    uITapGestureRecognizer.RequireGestureRecognizerToFail(uILongPressGestureRecognizer);
                }
                list.Add(uITapGestureRecognizer);
                //uITapGestureRecognizer.ShouldReceiveTouch = (recognizer, touch) => {
                //	return _element.get_IgnoreChildrenTouches() ? touch.View==_view : true;
                //};
            }
            if (HandlesPans)
            {
                var uIPanGestureRecognizer = new UIPanGestureRecognizer(new Action <UIPanGestureRecognizer>(OnPanned));
                uIPanGestureRecognizer.MinimumNumberOfTouches        = 1;
                uIPanGestureRecognizer.ShouldRecognizeSimultaneously = ((thisGr, otherGr) => true);
                list.Add(uIPanGestureRecognizer);
                //uIPanGestureRecognizer.ShouldReceiveTouch = (recognizer, touch) => {
                //	return _element.get_IgnoreChildrenTouches() ? touch.View==_view : true;
                //};
            }
            if (HandlesPinches)
            {
                var uIPinchGestureRecognizer = new UIPinchGestureRecognizer(new Action <UIPinchGestureRecognizer>(OnPinched));
                uIPinchGestureRecognizer.ShouldRecognizeSimultaneously = ((thisGr, otherGr) => true);
                list.Add(uIPinchGestureRecognizer);
                //uIPinchGestureRecognizer.ShouldReceiveTouch = (recognizer, touch) => {
                //	return _element.get_IgnoreChildrenTouches() ? touch.View==_view : true;
                //};
            }
            if (HandlesRotates)
            {
                var uIRotationGestureRecognizer = new UIRotationGestureRecognizer(new Action <UIRotationGestureRecognizer>(OnRotated));
                uIRotationGestureRecognizer.ShouldRecognizeSimultaneously = ((thisGr, otherGr) => true);
                list.Add(uIRotationGestureRecognizer);
                //uIRotationGestureRecognizer.ShouldReceiveTouch = (recognizer, touch) => {
                //	return _element.get_IgnoreChildrenTouches() ? touch.View==_view : true;
                //};
            }

            /*
             *          var control = (UIView)_view.GetPropertyValue ("Control");
             *          if (control is UIButton)
             *                  control.UserInteractionEnabled = !(HandlesTaps || HandlesDownUps);
             */
            return(list.ToArray());
        }