How to drag and dismiss View Controller? - ios

I would I accomplish this?
On Facebook, when we tap a gallery of pictures, it shows what appears to be a Table View Controller. And when we scroll to the top or to the end of the table, the view starts to dismiss. But it only fully dismisses when we actually release the finger from the screen.
The new Apple Music App also has this feature. It shows on the screen with the controls and the album's photo (when we're playing a song). We can do a pan gesture there, along the Y axis, and the view moves with the finger. And the view doesn't dismiss until we actually release the finger from the screen.
How can I implement this behaviour? And what API's should I be looking into? Is there an example you could point me to?
Thank you!

You may want to check out UIPresentationController. I haven't used them myself, but they may be what you are looking for.

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.

How to implement swipe views with CollectionView/TableView Controllers?

I am creating an app using Swift, and I'm still trying to figure out what the best configuration would be.
What I'd like to have is 3 screens (the left screen would have a side out panel) that users can access via the navigation bar menu or just by swiping left/right the screen for more accessibility.
I could easily create my TableViewControllers/CollectionViewController and the menu, but I'm struggling at making the screen able to detect users gestures at the same time, and I'm not sure whether I should use 3 View Controllers and then add the Collection View/Table View via the Storyboard, or directly use the CollectionViewController/TableViewController
I added a picture here describing what I'd like to accomplish:
Also, I wonder whether I should use storyboards or not for my project.
I know that's a lot of questions !
Any ideas please ?
Thank you very much and have a good day,
J.
You need to add 2 "swipe gesture recogniser"s to your middle screen(your second screen in your attached image) , and set one for identifying left swipe and another for right swipe. Create action methods for both in your view controller and add code accessing left screen and right screen in respective methods.
note - you need to drag "swipe gesture recogniser" to top bar of your view controller scene to add it.
You can use a scrollview as a container, put three ViewController in it.

drag behavior similar to loop dragging in iOS garage band

What's the best way to drag something out of a UIPopoverController, similar to how loops get dragged from the loop browser (I'm assuming it's a UIPopoverController) in Garageband on iOS? Meaning, the popover gets dismissed as soon as the user drags outside of it.
I tried implementing it via gestures, but as soon as I dismiss the popover, the gestures and therefore the dragging gets invalidated.
Is there a way to hide the popover, so I can dismiss it at the end of the drag? Or are there more elegant solutions?

iOS view push transitions with visible next view

I'm trying to achieve a view transition style, the one that you can see when you slide from the left side of the screen towards the middle if you're in a view that can go back. (find any app that has a back button somewhere, and just swipe from left to right starting from the edge of the screen).
The difference between this and a regular push transition is that you can see the next AND current views on the same screen and, as you slide (if you go slowly) you can really see the view and "play" with it. But right now what it does it simply quickly slide (with black on the back) and show the next view.
I'd like to be able to do that between some of my views and i have no idea how to achieve that. I'm just using a custom segue that goes left to right or right to left but that's pretty much it.
Any idea how to achieve that?
If you are using a UINavigationController and the pushViewController:animated method, then this should be the default functionality on iOS 7.0 and later. Your new UIViewController will be able to be "pulled back" by the user using a swipe right from the left of the screen.

Resources