Using Pan gesture recognizer to bring down a view controller - ios

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.

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.

Drag Back to Previous View Controller

When I push a new view controller in my app, I can pan from the very leftmost side of the screen and drag the view off (to the right) so that I'm back at the parent view controller. The motion follows my finger; I can drag it halfway and then back to the left if I want. This is built in.
I'm wanting to extend this functionality to the entire view. I want to be able to drag right from the center of the view and have it 'segue' back to the previous view controller, but not go all the way until my finger is released. It doesn't seem like a swipe gesture recognizer is what I want because that will segue all in one action. I have done some searching but I don't think I should have to implement a page view controller or a scroll view since similar functionality already exists.
What can I do to either modify the existing drag functionality or add a new gesture recognizer to accomplish this?

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.

How to make UIPageViewController transition behaviour like the interactive pop transition style in IOS7

In IOS7, when we pan on the screen edge to right, it will return the previous view controller. Also the transition is interactive, i.e., when we stop panning right, or panning distance is too short, the transition will not finished.
After reading others' blog, I know it can be called interactive pop transition.
The UIPageViewController contains many content ViewControllers, when swiping/panning the screen, we can view the different view controller, but the transition is too simple for me.
And following is my question:
I want to make the transition style in UIPageViewController like the mentioned above (interactive pop transition). They are difference in many ways, for example the previous view controller should be little darker.
And I do not want to custom my own transition style in this way, I just want to use the interactive pop transition in IOS7 default offered.
So maybe I should take some binding work? or assign some transition action in some where?
You should search for the style of interactive pop transition, and follow this custom your own transition.

Resources