How do I create two custom segues, one for each direction? - ios

I was able to look up a way to transition between two ViewControllers using a UIScrollView that I can use as a transition between two VCs.
I have an issue however, I have a TableView with cells that trigger a different kind of segue when tapped. (The Segue is some labels move to the new VC and other stuff appears)
I then want to be able to swipe back and forth all while the first animation is controlled by how much I swiped between. For example. if the user swipes just a small bit I want the animations to reverse back, so that if he changes his mind, he can still stay on his current VC. But if he wants to go back to the old VC, the labels animate back in place.
Basically like Snapchat but only one to go back, and the labels revert back. The other way is by tapping.
Here is a video mockup of the animation, please excuse its crudeness

You need to read up on transition controllers. What you want to do is to create a custom transition controller, specifically a UIPercentDrivenInteractiveTransition. Take a look at this tutorial on the subject:
custom UIViewController Transitions

Related

Swift Default Swipe Back - Animation

i am trying to make a swipe back animation in my App. It is working completely fine, but there are two problems I have.
The First one is, that the back swipe is working on the complete page and not only on the left side of my display.
And the second questions is, how can I have this normal back swipe animation. In my App it directly pops up.
At the moment I am only using ViewController and to switch between them I use a button with perform segue. But to get back to the pervious page I would like to use this default swipe back animation Apple is having.
Well there are multiple things happening.
the best way to handle this is to embed your first view controller inside UINavigationViewController. You can then push your second view controller and so you will get that Apple back-animation for free.
if you don't want to use NavigationController, you can at least replace that swipe recognizer with UIScreenEdgePanGestureRecognizer, so it will trigger only near the edges of screen. But it will still just pop instantly. You can't easily replicate that back animation... you'd need to use custom transition with
UIViewControllerTransitioningDelegate. And that's not easy.
My advice: learn more about UINavigationController and use it.

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.

Transition of a view controller embedded in a navigation controller

I have a problem with a transition. I am modifying this project https://github.com/xxxAIRINxxx/MusicPlayerTransition in order to have the transition from the right instead of the bottom. This part is fine. My transition comes from the right.
My problem is that I'm embedding the presented modal view controller into a Navigation Controller. I do this so I can use the "pushViewController" function when I click on a cell of my modal view controller.
My hierarchy is as follow. I have a dashboard. From the right, I drag a TableViewController X. If I drag back in the opposite direction, I come back to my dashboard. Fine. Now, If I tap a cell, it pushes a new ViewController Y.
Now, if I am in my new ViewController Y and that I drag back, I come back directly on my dashboard instead of going back to my TableViewController X, as a natural navigation controller should behave.
I did a small project on github that does only that, so you can easily see my entire code.
https://github.com/magohamote/NavigationControllerTransition.git
I understand why it behaves like this, but I would like to know how I can override the transition set on the navigation controller in order to have the normal behaviour of my navigation controller once it is presented.
Another problem I have not been able to solve. On the project I used as a starter (the one from xxxAIRINxxx) the transition is perfectly smooth. On mine, the first time I trigger the transition, it blinks and get stuck. Once I did it once, it is smooth the next time I drag my view. But the first time is always awful. I don't know why either :(
Thank you a lot for your help!

iOS : Swipe Gesture Push in one ViewController?

I want to add two swipe gesture. I did the code, and it's running, my text in the viewcontroller change when i touch the screen.
BUT, i want to add a "effect" when the user wants to slide at the next (or the previous) news, because currently, i'm just changing the text.
i tried to add action in the storyboard, to add push on the swipe with the view.
It's running, but there are two problems :
The push, seems to have a problem, because, when i want to slide on the previous news, the push effect comes right to left. (and not left - right)
I can't only change the contents without touch the navigation bar ? (because when i slide, the navigation bar loose him title, etc..)
If I understood you correctly you might want to use a UIScrollView. This will give you a nice animation.
You need a UIScrollView and add two of your ViewControllers as subviews.
Here are links to some ScollView tutorials:
Are there any good UIScrollView Tutorials on the net?
Pushing on the navigation controller stack is to the right if you want to go back to opposite direction instead of pushing, you should pop like so: [self.navigationController popViewControllerAnimated:YES]; You could paste some code in your question :)

how to swipe across UINavigationController tree leaves without pushing?

This app provides 6 screens of detail form input that are accessed through a master table view using a UINavigationController.
So the user starts are the master screen used as a menu, and drills down each of the detail view in turn. The depth of the tree is 2: at level 1, there is the master view (the menu). At level 2, there are all the 6 detail views.
Now, the most common workflow is to go through each of the 6 detail screens in turn, in a linear fashion. Having to go back to the menu each time is cumbersome at best.
I would therefore like to offer the user the possibility to go from one detail screen to the next or previous with a swipe gesture.
How can I do that?
I can set up 2 UIGestureRecognisers. No problem. I even linked them to a push segue, and it works, but this is not the behaviour I'd like: I want the depth to stay at 2. In other words, I would like the segues to replace not push the view at the top of the navigation stack.
What would be the best way?
Second: the views switch one the swipe gesture is over. I would rather have the animation start during the swipe, with the user having the opportunity to change her mind when watching the next/previous view partially appear, exactly as the photo app handled swiping from one photo to the next/previous.
Is that even possible?
Thanks for any insight.
It looks to me that you are looking for something like UIPageViewController with UIPageViewControllerTransitionStyleScroll.
You can segue to that UIPageViewController from your master tableView and add your 6 detail VC to it as pages.
Here is a tutorial on how to use a UIPageViewController in a storyboard.
Please note that this scroll style is only available on iOS6.0+.

Resources