2014-02-21 22 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