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

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.

Related

Default interactivePopGestureRecognizer from anywhere on screen

The default interactivePopGestureRecognizer only works if you swipe left to right on the left edge of the screen. I would like to be able to perform this gesture by swiping anywhere on my screen. Apps like Reddit, Slack and Twitter have implemented this gesture, so I know it is possible.
So far, I have successfully popped to the previous VC using a swipe gesture self.navigationController.popViewControllerAnimated(true), however it does not show the top stack during the swipe. This action performs an immediate and quick animated transition to the other stack. I would like the animation to be similar to the default and slowly "peel away" the stack as the finger is dragged across the screen. This leads me to believe that it is possible to do this with a pan Gesture, however I am unsure how to slowly move the current view controller out of the frame and reveal the next stack during translation.
EDIT: SOLUTION
Here is the solution: https://stackoverflow.com/a/35510861/9159691
I think this is easier than the suggested solution and also works for all viewControllers inside that navigation and also for nested scrollviews.
https://stackoverflow.com/a/58779146/8517882
Just install the pod and then use EZNavigationController instead of UINavigationController to have this behavior on all view controllers inside that navigation controller.

Using Pan gesture recognizer to bring down a view controller

I want to be able to swipe down on my main view controller and have my second view controller be brought down from above. I want this transition to be interactive in the sense that you can go back and forth between VCs without having to complete the whole transition (following the finger of the user like a scrollview with paging does).
This is effect can be seen when sliding between View Controllers on the new snapchat update. When you first open the app you are on the camera screen. If you swipe in any direction (up, down, left or right) the corresponding view comes in and covers the camera screen. When you swipe between views they are all essentially covering the main view (not moving it of to the side like in many tutorials i find online which use scrollview to achieve this effect).
Essentially it would look like a vertical page view controller, but instead of moving the current view controller off the screen as the new one comes in, the new one would cover the current one until it is completely on top of it.
From what I understand, a pan gesture recognizer could do the trick.
Does anyone know how I can go about doing this. I have been searching forever and can not seem to figure it out.
I want to be able to swipe down on my main view controller and have my second view controller be brought down from above. I want this transition to be interactive
Okay, so you are describing a custom interactive transition animation. The exact details for how you implement this depend on whether you want this to be a push transition or a present (modal) transition. I assume it is to be a presentation (modal) transition.
So you will start by setting the presented view controller's transitioningDelegate. Everything takes off from there. The pan gesture recognizer will call present,
and the transitioning delegate's delegate methods will be called:
animationController(forPresented:presenting:source:)
interactionControllerForPresentation(using:)
The interaction controller that you return from the second method is responsible to responding to each change in the pan gesture by updating the "frame" of the animation (as well as the transition coordinator).
If this is for iOS 10 only, this is very easy because you can use the UIViewPropertyAnimator. It has the remarkable ability to "hurry" to the end or start of the animation when the gesture ends and you decide to complete or cancel the animation. Otherwise, you're probably best off using a UIPercentDrivenInteractiveTransition object to help you.

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.

Detect swipe events on UIPageView below UITableView

So my problem is the following:
I have a UIViewController, in it I have defined a UIPageViewController and added its view to the hierarchy and on top of that I have added an UITableView.
What I would like is to be able to scroll my UITableView (that part works) but also to be able to swipe to change the slides of my UIPageViewController.
My problem is that the UIPageViewController doesn't detect the swipe gesture at all. If I remove the UITableView it works all right of course.
My question is the following: is there any way to pass the swipe events from the UITableView to the UIPageViewController so both would receive their intended gestures ?
You would need to have the tableView inside your page view (in the content view controller for a specific page).
If you have two views on top of each other the front one will intercept all the touches and no actions will make it through to the lower views.
Try setting user interaction on the tableView to false to see what I am talking about. Of course this will cause the tableView to become unresponsive. You will need to implement this a different way.

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.

Resources