void ClearCloserRecognizer(UIScrollView scrollView) { if (_globalCloser == null || _globalCloser.State == UIGestureRecognizerState.Cancelled) { return; } var cell = GetContextCell(scrollView); cell.RemoveGestureRecognizer(_closer); _closer.Dispose(); _closer = null; _table.RemoveGestureRecognizer(_globalCloser); _table = null; _globalCloser.Dispose(); _globalCloser = null; }
public override void WillEndDragging(UIScrollView scrollView, PointF velocity, ref PointF targetContentOffset) { if (ShouldIgnoreScrolling(scrollView)) { return; } var rightwidth = RightButtonsWidth; var leftwidth = LeftButtonsWidth; var x = targetContentOffset.X; var parentThreshold = scrollView.Frame.Width * .4f; var contentRightThreshold = rightwidth * .8f; var contentLeftThreshold = leftwidth * .8f; if ((x >= parentThreshold || x >= contentRightThreshold) || (x <= -parentThreshold || x <= -contentLeftThreshold)) { if (x >= parentThreshold || x >= contentRightThreshold) { IsRightOpen = true; IsLeftOpen = false; targetContentOffset = new PointF(rightwidth, 0); } else if (x <= -parentThreshold || x <= -contentLeftThreshold) { IsRightOpen = false; IsLeftOpen = true; targetContentOffset = new PointF(-leftwidth, 0); } RemoveHighlight(scrollView); if (_globalCloser == null) { UIView view = scrollView; while (view.Superview != null) { view = view.Superview; NSAction close = () => { if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { RestoreHighlight(scrollView); } IsRightOpen = false; IsLeftOpen = false; scrollView.SetContentOffset(new PointF(0, 0), true); ClearCloserRecognizer(scrollView); }; var table = view as UITableView; if (table != null) { _table = table; _globalCloser = new GlobalCloseContextGestureRecognizer(scrollView, close); _globalCloser.ShouldRecognizeSimultaneously = (recognizer, r) => r == _table.PanGestureRecognizer; table.AddGestureRecognizer(_globalCloser); _closer = new UITapGestureRecognizer(close); var cell = GetContextCell(scrollView); cell.AddGestureRecognizer(_closer); } } } } else { ClearCloserRecognizer(scrollView); IsRightOpen = false; IsLeftOpen = false; targetContentOffset = new PointF(0, 0); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { RestoreHighlight(scrollView); } } }