GestureRecogniser not working when going back - ios

I am using SWRevealController class to add a sidebar. This adds a gesture recogniser for a swipe.
I have a table with a few choices and initially the swipe works fine. However, if I select a choice, go to the new page and then come back via the nav, the swipe STOPS working (however the button for the sidebar still works).
This is the code for the swipe added to viewDidLoad
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
What do I need to do to fix it?

Call [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer]; in viewWillAppear instead of viewDidLoad so that it is replaced following each transition. A gesture can only be attached to one view at a time so when you attach it to a different view it gets removed from the first.
Alternatively, consider adding the gesture to a more root view (like the window / navigation bar) depending on what interaction you want to enable.

Related

Two Swipe Gesture Recognizer on ViewController, only one works?

I have two Swipe Gesture Recognizers on my ViewController. One works fine, when I swipe right it goes back to the previous View. However, the recent one I added doesn't work at all. I have set it to go to a different View Controller when I swipe left but, nothing happens. I didn't add any code for the first Swipe Gesture Recognizer so shouldn't this additional one also be able to work without code?
It goes back because the interactivePopGestureRecognizer handles that, not your swipe recognizer.
You need to do two things:
Wire your gesture recognizers to IBAction calls within your view controller so that it can handle them
Disable the pop gesture recognizer so that it will not conflict with your desired behavior (See answer here for how)

Prefer swipe to delete over a competing swipe gesture

So I have a tableViewController inside a XLPagerTabStrip view controller, basically a pod which allows me to swipe between child view controllers left and right. The problem is that I want to disable the view controller scroll when the user swipes on a cell on my tableView. In this case I want him to be able to see the delete option, instead of changing the viewController itself. Is this possible? Currently, I see the delete button only if I swipe really, really fast and in all other scenarios, the entire viewController is swiped away.
I don't believe there is any sort of preference property for UIGestures. Instead, I believe the rule is the first gesture added takes precedent. However, in your specific circumstance with XLPagerTabStrip, you can simply disable scrolling in the interface builder for your 'containerView' (subclass of UIScrollView). That solved the problem for me anyway, having my children view controllers' UITableViews actions appearing correctly.

Swift: UIPageViewController - Navigate view controllers with swipe from edge of screen

I am new to UIPageViewControllers and can't seem to find a solution elsewhere. I have a working UIPageViewController with 3 different viewControllers. Right now you can navigate to a different viewController by swiping left or right starting at any point on the screen. However, I only want to navigate to a different viewController when I swipe over from the right or left edge of the screen. Similar to how the Screen Edge Pan Gesture works. Is this possible? If so, how would I go about implementing this in my program.
What I do in this situation is to attach gesture recognizers to the views of the "3 different viewControllers", that is, the child view controllers of the page view controller. These gesture recognizers' action methods post notifications. In the view controller that controls the page view controller, I receive these notifications and call setViewControllers:direction:animated: to perform the appropriate slide.
UIPageViewController has and embedded gesture recognizers that to the trick. Normally you have no influence on them. You could get to them by calling gestureRecognizers method on UIPageViewController's view and see what you can do with them from there.

Activate Pan Gesture on MenuController using ECSlidingViewController

I'm currently using ECSlidingViewController in my app. As default behaviour, it's possible to show the side menu (MenuViewController or underRightViewController) panning on the top view or calling the RevealMenu: method.
I extended this functionality giving the user the possibility to pan the top view controller back adding this line to the UnderLeftViewController ViewDidLoad method:
self.slidingViewController.shouldAllowUserInteractionsWhenAnchored = YES;
(source here)
Here the limitations:
User must touch the top view on the side to pan it back,touching the MenuController cell won't have any effect. If you look at the Facebook iOS you will notice it's possible to pan the top view starting the gesture in the middle of the side tableviews.
adding the above line of code will disable the TapRecogniser previously active on the top view (and I would need it to work at the same time of the Pan recogniser).
Does anybody know how to implement this behavior?
Ok, I might have found a work around for the tap recogniser problem, instead of the previous line insert this one in your side menu view controller
self.slidingViewController.shouldAddPanGestureRecognizerToTopViewSnapshot = YES;
still it's not possible to swipe on the menu view though,but at least I have swipe and tap events working on the top view once is on the side.

Embedded UINavigationController's back button does not work

I'm using a Container View control through interface builder to embedded a UINavigationController and its stack into my app.
The problem I'm having is that the back button does not work on all pushed VCs over the Root VC.
You press the automatically generated back button on these pushed VCs and nothing happens.
Edit:
There is no code written. Its all set up in IB at the moment.
As you can see...Container View with its embedded view controller set to the UInavigation Controller. The whitespace on the left will be a swipeable menu eventually - thats the reason for the set up. Then there's a next button on the root RV which segues to a second view controller.
That state is shown above. Pressing the back button (labelled test) does nothing. Normally it would pop the top view controller and go back to 'test'. Clearly the embedding is interfering with the normal UINavigiationController function somehow.
I just dont know how.
Another Edit:
Making a custom button on that top View Controller and manually calling
[self.navigationController popViewControllerAnimated:true];
Actually works and the top view controller is removed from the stack.
So the question is why does the back button not work?
I had a similar problem when I forgot that I added a tap gesture recognizer to my navigation bar. The back button actually received touches (pushed state) but as in your example did nothing. A custom button on the navigation bar worked though.
Once I removed the gesture recognizer the back button worked again.
Maybe some other view/or gesture recognizer in your container view is catching the touches...

Resources