Configuring UIPageViewController gesture recognizers.

I want to implement the -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch gesture delegate in the pageviewcontroller.m file , but I cannot get any gesture like:

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;
}

in the above code, self indicates a pageview.

therefore, I cannot assign a delegate to pageviewcontroller gestures.

Edited Part:

OK I realized I don’t have a gesture object due to the uipageviewscroll style.

But I have a problem, I need to turn off the hardview arrow pageviewcontroller , and you need to scroll the viewcontroller page with two buttons, for example, if the user is trying to pan, and the starting point is inside my uibuttons frame, and then the viewviewcontroller should not scroll otherwise.

transitionStyle UIPageViewControllerTransitionStyleScroll.

...

+4
1

.

, scorll

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

.

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

[g1 setDelegate:self];

[pagescrollview addGestureRecognizer:g1];

gesture , , , , , , .

-(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;
}

, - .

+7

Source: https://habr.com/ru/post/1528046/


All Articles