shoujo_sm
shoujo_sm

Reputation: 3203

UIScreenEdgePanGestureRecognizer to activate SWRevealViewController pan gesture

I am using SWRevealViewController for sidebars and I have to use swipe for my previous and next stories and edge pan for sidebars.

The reason I use UIScreenEdgePanGestureRecognizer instead of PanGestureRecogniser is because swipe will end up call pan gesture which causes the whole page a mess. I hoping there is a way to call pan gesture when edge pan recogniser activated instead of using this:

[self.view addGestureRecognizer:[MainViewController sharedInstance].revealViewController.panGestureRecognizer];


[[BTHomeViewController sharedInstance].revealViewController.panGestureRecognizer requireGestureRecognizerToFail: left];
[[BTHomeViewController sharedInstance].revealViewController.panGestureRecognizer requireGestureRecognizerToFail: right];

I want to use delegate of SWRevealVC. If there is any other way, please suggest it to me.

UIScreenEdgePanGestureRecognizer *panLeft = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(_handleRevealGesture:)];
[panLeft setEdges:UIRectEdgeLeft];
panLeft.minimumNumberOfTouches = 1;
panLeft.maximumNumberOfTouches = 1;
[self.view addGestureRecognizer:panLeft];

Delegate Methods of SWRevealVC

// The following methods provide a means to track the evolution of the gesture recognizer.
// The 'location' parameter is the X origin coordinate of the front view as the user drags it
// The 'progress' parameter is a positive value from 0 to 1 indicating the front view location relative to the
// rearRevealWidth or rightRevealWidth. 1 is fully revealed, dragging ocurring in the overDraw region will result in values above 1.
- (void)revealController:(SWRevealViewController *)revealController panGestureBeganFromLocation:(CGFloat)location progress:(CGFloat)progress;
- (void)revealController:(SWRevealViewController *)revealController panGestureMovedToLocation:(CGFloat)location progress:(CGFloat)progress;
- (void)revealController:(SWRevealViewController *)revealController panGestureEndedToLocation:(CGFloat)location progress:(CGFloat)progress;

Upvotes: 3

Views: 1123

Answers (1)

Shardul
Shardul

Reputation: 4274

To replace UIPanGestureRecognizer with UIScreenEdgePanGestureRecognizer just do this:

  • Go to SWRevealViewController
  • Find and replace UIPanGestureRecognizer with UIScreenEdgePanGestureRecognizer
  • Most IMPORTANT set edges

    _panGestureRecognizer.edges = UIRectEdgeLeft;

Upvotes: 5

Related Questions