How do I get vertical swipes in a page view controller - ios

I want a user to normally be able to swipe right to left through the pages of the page view controller, but I also want the user to swipe up on a page to save the content of that page. So far I have tried adding a gesture recogniser but it interferes with the page view controller. I have tried many thins like adding the gesture recogniser to the window, or a hidden view but it keeps messing with the page view controller.
All in all is there a way that mainly horizontal swipes get picked up by the page view controller(so they move to the next viewcontroller), but vertical swipes are picked by by me and I can play an animation and trigger a function or something...

It looks like UIPageViewController exposes its gesture recognizers with the property gestureRecognizers.
You should be able to attach your swipe up gesture recognizer to the page's view.
You'd then tell your gesture recognizer that it should only work when the page view controler's gesture recognizers fail. You'd call your gesture recognizer's require(toFail:) method for each of the page view controller's gesture recognizers.
(You should read the Xcode documentation on UIGestureRecognizer. It explains how you can set up dependencies between gesture recognizers so that one has to fail before the next one will evaluate, for situations like this one.)

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)

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.

Swift: Navigate ViewControllers with UIPageController or Screen Edge Pan Gesture Recognizer

I have 4 ViewControllers that I want to navigate through by swiping left and right from the edge of the screen. I am fairly new to ios, so was just wondering if it would be more beneficial to activate a segue by using a Screen Edge Pan Gesture Recognizer or by using a UIPageViewController. It is worth noting that the ViewControllers all contain gesture recognizers, imageViews, textViews' etc. I do only want to switchviewControllers` when swiped from the edge of the screen.
If you use edge swipe gesture recognizer, you're going to have to write code to manage the view controllers. If you're new to iOS, I might suggest using the page view controller, so it gets you out of the weeds of managing this yourself.
Both can work, but I'd suggest starting with the page view controller and only "roll your own" if the page view controller doesn't give you the control that you need.

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.

How to detect swipe gesture in a tiny view?

I already know how to attach a swipe gesture to view.
Suppose I have a tiny view (0,0,5,5).When I swipe in it, the action with that gesture is not trigger. Then I debugged, I found out the tap event I attached with this view interfere the swipe. How can I make the swipe action trigger with that tiny view?
Summary, with a same view, if it's tiny - the Tap gesture will handle the action. If it's bigger, the swipe gesture will handle it.

Resources