protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); _page = (GesturedContentPage)e.NewElement; // Subscribe to the events here if (_page.CaptureSwipeRightToLeft) { NativeView.AddGestureRecognizer(new UISwipeGestureRecognizer(g => _page.OnSwipeRightToLeft()) { Direction = UISwipeGestureRecognizerDirection.Left }); } if (_page.CaptureSwipeLeftToRight) { NativeView.AddGestureRecognizer(new UISwipeGestureRecognizer(g => _page.OnSwipeLeftToRight()) { Direction = UISwipeGestureRecognizerDirection.Right }); } if (_page.CaptureSwipeBottomToTop) { NativeView.AddGestureRecognizer(new UISwipeGestureRecognizer(g => _page.OnSwipeBottomToTop()) { Direction = UISwipeGestureRecognizerDirection.Up }); } if (_page.CaptureSwipeTopToBottom) { NativeView.AddGestureRecognizer(new UISwipeGestureRecognizer(g => _page.OnSwipeTopToBottom()) { Direction = UISwipeGestureRecognizerDirection.Down }); } if (_page.CaptureTap) { NativeView.AddGestureRecognizer(new UITapGestureRecognizer(g => _page.OnTap()) { NumberOfTapsRequired = 1 }); } if (_page.CaptureLongTap) { NativeView.AddGestureRecognizer(new UILongPressGestureRecognizer(g => _page.OnLongTap())); } }
public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { // Right to left swipe if (e1.GetX() - e2.GetX() > MinSwipeDistance && Math.Abs(velocityX) > SwipeThreadsholdVelocity) { if (_page.CaptureSwipeRightToLeft) { _page.OnSwipeRightToLeft(); } } // Left to right swipe else if (e2.GetX() - e1.GetX() > MinSwipeDistance && Math.Abs(velocityX) > SwipeThreadsholdVelocity) { if (_page.CaptureSwipeLeftToRight) { _page.OnSwipeLeftToRight(); } } if (e1.GetY() - e2.GetY() > MinSwipeDistance && Math.Abs(velocityY) > SwipeThreadsholdVelocity) { if (_page.CaptureSwipeBottomToTop) { _page.OnSwipeBottomToTop(); } } // Left to right swipe else if (e2.GetY() - e1.GetY() > MinSwipeDistance && Math.Abs(velocityY) > SwipeThreadsholdVelocity) { if (_page.CaptureSwipeTopToBottom) { _page.OnSwipeTopToBottom(); } } return(true); }