2012-05-21 165 views
0

我有一個UIPageViewController,每個頁面包含頁面上的多個UIViews,每個UIView允許在長按手勢後的Pan手勢,我在contentVC中使用下面的委託,但它出現了pageVC不關心我的限制,它繼續翻頁!當我在平移時,是否必須做任何事情來禁用翻頁? (不得已將設置在PageVC像canTurn的變量,並將其設置爲NO,而平移是在行動....禁用UIPageViewController手勢識別器,同時處理longPressed手勢

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ 

    if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && 
     [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) { 
     return YES; 
    } 
    return NO; 
} 

回答

1

你應該在PageVC添加-gestureRecognizer:shouldReceiveTouch:方法本身,或如果你不想要的PageVC自身添加它,你可以讓一個委託處理它

像:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 
{ 
    if(someCase) 
    { 
     return yes; 
    } 

    return no; 
} 

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 
{ 
    return [delegate shouldHandle:.....]; 
} 
+0

什麼PageVC? PageViewController的子類? –

+0

是的UIPageViewController的子類 –

+2

這是永遠不會被調用的。我應該首先設置gestureRecoqnizer委託嗎? –