Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWRevealViewController add gesture to entire front view

Right now I am using SWRevealViewController class in my project. The basic functionality allows me to swap front view by pressing navigation bar button. But I want to add gesture to entire view.

I can add this code and it works for my button.

[self.startTestButton addGestureRecognizer:self.revealViewController.panGestureRecognizer];

But it just works for the one UI element. So I can't add, for example, other UI element to this gesture.

This code below shows how panGestureRecognizer method has been written:

- (UIPanGestureRecognizer*)panGestureRecognizer
{
    if ( _panGestureRecognizer == nil )
    {
        SWDirectionPanGestureRecognizer *customRecognizer =
            [[SWDirectionPanGestureRecognizer alloc] initWithTarget:self action:@selector(_handleRevealGesture:)];

        customRecognizer.direction = SWDirectionPanGestureRecognizerHorizontal;
        customRecognizer.delegate = self;
        _panGestureRecognizer = customRecognizer ;
    }
    return _panGestureRecognizer;
}
like image 808
Matrosov Oleksandr Avatar asked Dec 09 '22 14:12

Matrosov Oleksandr


1 Answers

To add the gesture recognizer to the whole view just add it to the whole view instead of just a single button. I'm using SWRevealViewController and my main view is a UITableView so to get the gesture recognizer to work on the whole view I have this in the viewDidLoad method of my UIViewController:

[self.tableView addGestureRecognizer: self.revealViewController.panGestureRecognizer];

So, just add the recognizer to the view you like. For most UIViewContollers this will be self.view.

Obviously if any controls or subviews of the view have their own gesture recognisers, these will take precedence of the one on the top level view, such that the panning will only work in the areas not occupied by those subviews.

like image 52
mluisbrown Avatar answered Dec 21 '22 14:12

mluisbrown