Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing UIPageViewController gesture recognizers Scroll behavior

I want to implement -(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch gesture delegate in pageviewcontroller.m file but i can't get any gesture as:

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 above code self is pointing towards pageviewcontroller.

therefore i can't assign delegate to pageviewcontroller gestures.

Edited Part:

OK I got it, I am not getting any gesture object because of uipageviewscroll style.

But I have a problem I need to disable pageviewcontroller pan gesture and need to scroll the pageviewcontroller from two buttons, like if user try to pan, and it's starting point is inside my uibuttons frame then pageviewcontroller should scroll otherwise not.

I am using transitionStyle UIPageViewControllerTransitionStyleScroll.

Any solution for this... Thanks in advance

like image 332
Irfan Gul Avatar asked Feb 21 '14 07:02

Irfan Gul


1 Answers

After trying so many hacks, I finally got solution.

What i did, first got the pageviewcontroller scorll view in a property

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

Then assigned pan gesture to pageviewcontroller scorllview and gesture delegate.

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

[g1 setDelegate:self];

[pagescrollview addGestureRecognizer:g1];

Then in gesture delegate , i checked whether the gesture starts from my desire points, if starts from a location that should scroll pageviewcontroller then this delegate method should return no to enable original pagescorllview gesture to receive pan 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;
}

hope it help someone else.

like image 56
Irfan Gul Avatar answered Oct 05 '22 13:10

Irfan Gul