To add a Gesture to the entire front view using the SWRevealViewController using the storyboard, we must add
SWRevealViewController *revealController = [self revealViewController]; [revealController panGestureRecognizer]; [revealController tapGestureRecognizer];
in the FirstViewController application. Add an action and goal to the navigation bar, for example
_sidebarButton.target = self.revealViewController; _sidebarButton.action = @selector(revealToggle:); // Set the gesture [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
In SWRevealViewController.h add the following method, for example
- (UITapGestureRecognizer*)tapGestureRecognizer; - (BOOL)revealControllerTapGestureShouldBegin:(SWRevealViewController *)revealController;
In SWRevealViewController.m add
- (UITapGestureRecognizer*)tapGestureRecognizer { if ( _tapGestureRecognizer == nil ) { UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(_handleTapGesture:)]; tapRecognizer.delegate = self; [_contentView.frontView addGestureRecognizer:tapRecognizer]; _tapGestureRecognizer = tapRecognizer ; } return _tapGestureRecognizer;
}
- (void)_handleTapGesture:(UITapGestureRecognizer *)recognizer
{
NSTimeInterval duration = _toggleAnimationDuration; [self _setFrontViewPosition:FrontViewPositionLeft withDuration:duration];
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { if ( _animationQueue.count == 0 ) { if ( gestureRecognizer == _panGestureRecognizer ) // return [self _panGestureShouldBegin]; return ( gestureRecognizer == _panGestureRecognizer && _animationQueue.count == 0) ; if ( gestureRecognizer == _tapGestureRecognizer ) return [self _tapGestureShouldBegin]; } return NO;
}
In case of xib, you can directly use
https://github.com/John-Lluch/SWRevealViewController
source share