/// <summary> /// Initializes a new instance of the <see cref="SwipeRecognizer"/> class. /// </summary> /// <param name="view">The native view.</param> /// <param name="directionMask">Optional swipe direction mask.</param> /// <param name="numberOfTouchesRequired">Optional number of touches required.</param> public SwipeRecognizer(UIView view, SwipeDirection directionMask = Defaults.DirectionMask, int numberOfTouchesRequired = Defaults.NumberofTouchesRequired) : base(view, directionMask, numberOfTouchesRequired) { _recognizers = new List <UISwipeGestureRecognizer>(); if (directionMask.HasFlag(SwipeDirection.Left)) { var recognizer = new NativeSwipeGestureRecognizer(this, UISwipeGestureRecognizerDirection.Left); _recognizers.Add(recognizer); view.AddGestureRecognizer(recognizer); } if (directionMask.HasFlag(SwipeDirection.Right)) { var recognizer = new NativeSwipeGestureRecognizer(this, UISwipeGestureRecognizerDirection.Right); _recognizers.Add(recognizer); view.AddGestureRecognizer(recognizer); } if (directionMask.HasFlag(SwipeDirection.Up)) { var recognizer = new NativeSwipeGestureRecognizer(this, UISwipeGestureRecognizerDirection.Up); _recognizers.Add(recognizer); view.AddGestureRecognizer(recognizer); } if (directionMask.HasFlag(SwipeDirection.Down)) { var recognizer = new NativeSwipeGestureRecognizer(this, UISwipeGestureRecognizerDirection.Down); _recognizers.Add(recognizer); view.AddGestureRecognizer(recognizer); } }
bool ISwipeGestureController.DetectSwipe(View sender, SwipeDirection direction) { var detected = false; var threshold = Threshold; if (direction.HasFlag(SwipeDirection.Left)) { detected |= _totalX < -threshold; } if (direction.HasFlag(SwipeDirection.Right)) { detected |= _totalX > threshold; } if (direction.HasFlag(SwipeDirection.Down)) { detected |= _totalY > threshold; } if (direction.HasFlag(SwipeDirection.Up)) { detected |= _totalY < -threshold; } if (detected) { SendSwiped(sender, direction); } return(detected); }