簡體   English   中英

MonoTouch:如何將兩個手指手勢識別器添加到UIPageViewController?

[英]MonoTouch: How to add a two finger gesture recognizer to UIPageViewController?

具有PageCurl過渡的UIPageViewController非常適合模擬頁面,但是默認的GestureRecognizer(UIPanGestureRecognizer)僅響應一個手指事件。 我想在其他事件之上添加一個兩指事件。

如何將另一個PanGestureRecognizer添加到當前的UIPageViewController實例? 這個新的PanGestureRecognizer應該等待兩個手指的平移觸摸,而不禁用原始的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;

並使用此值采取相應措施。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM