MonoTouch:如何添加一个双指手势识别器到UIPageViewController



带有PageCurl转换的UIPageViewController对于模拟页面来说非常棒,但是默认的GestureRecognizer (UIPanGestureRecognizer)只响应一个手指事件。我想在其他事件的上方添加一个双指事件。

如何添加另一个PanGestureRecognizer到当前的UIPageViewController实例?这个新的PanGestureRecognizer应该等待两个手指的pan触摸,而不会禁用原来的UIPanGestureRecognizer。

我所需要的只是在用户用两个手指而不是一个手指滚动页面时触发一个额外的自定义事件,但它仍然应该像调用一个手指事件那样滚动页面。

我如何在MonoTouch中做到这一点?

我自己解决了这个问题。UIPageViewController包含一个手势识别器数组。第一个是我们需要获取的,将它的"MaximumNumberOfTouches"属性从1改为2。下面是代码:

UIPageViewController pageController = new UIPageViewController (UIPageViewControllerTransitionStyle.PageCurl, UIPageViewControllerNavigationOrientation.Horizontal, UIPageViewControllerSpineLocation.Min);
UIPanGestureRecognizer pan_gesture_recognizer = (UIPanGestureRecognizer) pageController.GestureRecognizers[0];
pan_gesture_recognizer.MaximumNumberOfTouches = 2;
然后,在你的代码中处理翻页事件(在我的情况下,一个自定义类继承"UIPageViewControllerDataSource"),你可以访问当前触摸的数量:
int number_of_touches = pageController.GestureRecognizers [0].NumberOfTouches;

最新更新