自定义UIPageViewController手势识别器滚动行为

Irf*_*Gul 5 uikit ios uipageviewcontroller

我想在pageviewcontroller.m文件中实现-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch 手势委托,但我不能得到任何手势:

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;
}
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,self指向pageviewcontroller.

因此我无法将委托分配给pageviewcontroller手势.

编辑部分:

好吧,我得到了它,因为uipageviewscroll样式,我没有得到任何手势对象.

但我有一个问题,我需要禁用pageviewcontroller 平移手势,需要从两个按钮滚动pageviewcontroller,如果用户尝试平移,它的起点是在我的uibuttons框架内,然后pageviewcontroller应该滚动否则不滚动.

我正在使用transitionStyle UIPageViewControllerTransitionStyleScroll.

任何解决方案...提前谢谢

Irf*_*Gul 8

在尝试了这么多黑客之后,我终于得到了解决方案.

我做了什么,首先得到了一个属性中的pageviewcontroller scorll视图

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

然后将pan手势分配给pageviewcontroller scorllview和手势委托.

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

[g1 setDelegate:self];

[pagescrollview addGestureRecognizer:g1];
Run Code Online (Sandbox Code Playgroud)

然后在手势委托中,我检查手势是否从我的愿望点开始,如果从应该滚动pageviewcontroller的位置开始,则该委托方法应该返回no以使原始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;
}
Run Code Online (Sandbox Code Playgroud)

希望它能帮助别人.