2014-02-21 24 views
4

我想實現pageviewcontroller.m文件-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch手勢代表,但我不能得到任何手勢:定製UIPageViewController手勢識別滾動行爲

NSArray *temp = self.gestureRecognizers; 
NSLog(@"count %i",temp.count); // this logs count 0 

NSArray *temp = self.view.gestureRecognizers; 
NSLog(@"count %i",temp.count); // this also logs count 0 

for (UIGestureRecognizer *gR in temp) { 
    gR.delegate = self; 
} 
在上面的代碼中自行

朝pageviewcontroller指向。

因此我無法將委託分配給pageviewcontroller手勢。

編輯部分:

好,我知道了,我沒有得到,因爲uipageviewscroll樣式的姿勢對象。

但是我有一個問題,我需要禁用pageviewcontroller 平移手勢,需要從兩個按鈕滾動pageviewcontroller,就像如果用戶試圖平移,它的出發點是我uibuttons框內然後pageviewcontroller應該否則滾動不。

我正在使用transitionStyle UIPageViewControllerTransitionStyleScroll

的任何解決方案,這... 在此先感謝

回答

7

試圖這麼多的黑客後,我終於得到了解決。

我做什麼,第一次拿到了pageviewcontroller scorll視圖屬性

for (UIView *view in mypageviewcontroller.view.subviews) { 
    if([view isKindOfClass:[UIScrollView class]]) 
    { 
     pagescrollview= (UIScrollView *)view; 
    } 
} 

然後分配平移姿態pageviewcontroller scorllview和手勢代表。

UIPanGestureRecognizer* g1 = [[UIPanGestureRecognizer alloc] initWithTarget:self              action:@selector(gesture)]; 

[g1 setDelegate:self]; 

[pagescrollview addGestureRecognizer:g1]; 

然後手勢代表,我查了姿勢是否從我的願望點開始,如果從一開始的位置應該滾動pageviewcontroller那麼這種委託方法應返回沒有使原pagescorllview手勢接收平移手勢。

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 
{ 
    if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) { 

    CGPoint touchPoint = [touch locationInView:self.view]; 
    if(floor(NSFoundationVersionNumber)<=NSFoundationVersionNumber_iOS_6_1) 
     touchPoint.y -=44; 
    else 
     touchPoint.y -=64; 

    PGNavigationController *nav =ViewControllerArray[VisiblePageindex]; 
    PageContentVC *pagecontentvc = ((PageContentVC *) nav.visibleViewController); 

    if (touchPoint.y > pagecontentvc.leftpanalbtn.frame.origin.y && (pagecontentvc.leftpanalbtn.frame.size.height+pagecontentvc.leftpanalbtn.frame.origin.y)>touchPoint.y && touchPoint.x >pagecontentvc.leftpanalbtn.frame.origin.x 
     && touchPoint.x<(pagecontentvc.leftpanalbtn.frame.origin.x+pagecontentvc.leftpanalbtn.frame.size.width)) { 
     return NO; 
    } 
    else if (touchPoint.y > pagecontentvc.rightpanalbtn.frame.origin.y && (pagecontentvc.rightpanalbtn.frame.size.height+pagecontentvc.rightpanalbtn.frame.origin.y)>touchPoint.y && touchPoint.x >pagecontentvc.rightpanalbtn.frame.origin.x 
      && touchPoint.x<(pagecontentvc.rightpanalbtn.frame.origin.x+pagecontentvc.rightpanalbtn.frame.size.width)) 
    { 

     return NO; 
    } 
    if(touchPoint.y>282 && touchPoint.x>118 &&touchPoint.y<282+75 && touchPoint.x < 118+85) 
    { 
     return NO; 
    } 
    // else if() 
    } 
    return YES; 
} 

希望它能幫助別人。

+1

@selector(手勢)在哪裏,它有什麼作用? – Jeff

+0

謝謝!這絕對有助於我,甚至三年後...... – Sakiboy