SergStav
SergStav

Reputation: 757

SWRevealViewController panGestureRecognizer with UIScreenEdgeGestureRecognizer

I've been looking for solution for this question,but didnt find any one. So I use SWRevealViewController for sidebar menu in my project but I want that side menu would open when user beging to touch from left edge of the view. I want this because I have another swipeGestureRecognizer for left and right swipe.For adding left and right swipes I'm use this code:

    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipedToRight:)];
        swipeRight.direction = UISwipeGestureRecognizerDirectionRight;

   UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @selector(swipedToLeft:)];
       swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;

So my question is how can I make that side menu would open only when touches begins from left edge?

UPD 1

I use this code to open side menu by panning at any part of the screen

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

And I have recognizer to swipe to right. The problem is once it open menu and once executes swipe's action. I want to allow to open menu only when touches is from left edge

UPD 2 Solved

I solved it by setting draggable border width:

self.revealViewController.draggableBorderWidth = self.view.frame.size.width / 2;

And now gesture from edge to center opens menu, and from center to right border executes swipe's action

Upvotes: 2

Views: 443

Answers (3)

John Dow
John Dow

Reputation: 26

What I would do is modify the already existent pop gesture that is built into the UINavigationController class.

Upvotes: 1

Wyetro
Wyetro

Reputation: 8588

What I would do is modify the already existent pop gesture that is built into the UINavigationController class.

Example code to add to your viewWillAppear:

if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    // Your code here
}

Upvotes: 1

CarlosGz
CarlosGz

Reputation: 396

You can add a UIPanGestureRecognizer as you mentioned before or add a subView in the top of your view and add a gesture to it:

UIView *topView = ...
[self.view addSubview: topView];

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]
                                   initWithTarget:self action:@selector(didPan:)];

[topView addGestureRecognizer:pan];

Upvotes: 1

Related Questions