John-Lluch / SWRevealViewController

A UIViewController subclass for presenting side view controllers inspired on the FaceBook and Wunderlist apps, done right !
Other
4.52k stars 989 forks source link

Stricted area for SWRevealViewController.PanGestureRecognizer #142

Closed phamquochoan closed 10 years ago

phamquochoan commented 10 years ago

Hi,

My project requires a Google map view with slide-out navigator view. This method: mapView.settings.consumeGesturesInView = NO allows SWReavealViewController works with a view which contains a google mapView.

The problem is every UIPanGestureRecognizer makes rearView and rightView appear. I want to strict the panGestures, if the starting point in one of these leftView and rightView then rearView and rightView shows up respectively

leftView = CGRectMake(0, 0, 25, self.view.bounds.size.height); rightView = CGRectMake(295, 0, 25, self.view.bounds.size.height);

If panGesture's starting point is outside of these views, then it moves the Google mapView.

And when there is a slide-out navigator view on the screen, the panGesture to make it disappear works as normal.

Can you help me please ? Thank you!

//Edit: my project's using storyboard. If the gestures to make rear and rightView appear and disappear have no effect on the map (currently it moves both the navigator view and map view) that would be great !

John-Lluch commented 10 years ago

You can implement the following delegate method to disable the pan gesture when you need to

or maybe you can set the draggableBorderWidth property to an appropriate value for your needs.

Thanks

phamquochoan commented 10 years ago

hi John, thanks for your response :) I haven't tested the delegate method in your reply yet, but draggableBorderWidth only locks the activate area of panGestureRecognizer, the map below still receives the gesture and it will move in this case. However, I've found another solution. Credit goes to https://github.com/kcharwood. I just modify some of his code.

- (void)viewDidLoad
{
self.view = _mapView;
    [[self.view.subviews[0] gestureRecognizers] enumerateObjectsUsingBlock:^(UIGestureRecognizer * gesture, NSUInteger idx, BOOL *stop){
        [gesture setDelegate:self];
    }];
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
    CGPoint location = [touch locationInView:self.view];
    CGRect boundingRect = self.view.bounds;
    if([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]){
        boundingRect.origin.x+=20;
        boundingRect.size.width-=40;
    }
    return CGRectContainsPoint(boundingRect, location);
}

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    return YES;
}

Note: adhere <UIGestureRecognizerDelegate> so gestureRecognizer: shouldRecognizeSimultaneouslyWithGestureRecognizer: will available.

20 and 40 mean the left and right area of the view. If the pan gestures starting location within these areas, the map won't move. /// And for closing the map, I got solution from here: https://github.com/John-Lluch/SWRevealViewController/issues/63 emixb's comment works flawlessly. However, for this specific case (using google map), the fastest way is mapView.setting setAllGestureDisable: YES

And it's done ! :)