3

带有PageCurl转换的UIPageViewController非常适合模拟页面,但默认的GestureRecognizer(UIPanGestureRecognizer)仅响应一个手指事件。我想添加一个两手指事件高于其他人。MonoTouch:如何添加双指手势识别器到UIPageViewController?

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

如果用户用两个手指而不是一个滚动页面,但是它仍然应该像调用一个手指事件一样滚动页面,所有我需要的是提升附加自定义事件的方法。

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

在此先感谢。

回答

10

我自己解决了这个问题。 UIPageViewController包含一组手势识别器。第一个是我们需要得到的,从1〜2这里改变其“MaximumNumberOfTouches”属性之一是代码:

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; 

,并使用这个值来采取相应的行动。

+1

您应该将您的问题标记为已回答。可以在stackoverflow中回答你自己的问题:) – poupou