Drag Back to Previous View Controller - ios

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?

Related

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 create sideway swipe with the View coming sideways? With Swift using Xcode

I am trying to create an iPhone app where you swipe right or left to get from one view to another. I know how to do it from scratch with my own code, but I want to learn the Apple way of doing it, which means drag and drop the UISwipeGestureRecognizer icon into the storyboard and change settings in some way. I can get it to have a sideway swipe, but not with the views appearing from the sides. Only have the view appear from the default bottom.
So frustrating not coding from scratch, don't know where the problem is. Help very much appreciated!
I don't think you are clear on whether you are trying to have "views" appear from the sides or "view controllers" appear from the sides. There is a distinction. What you wish to do in general is drag a swipe gesture recognizer and drop it onto the view you wish to recognize the gesture (for example the top level view of the scene). Then you need to control drag the gesture from the top of the scene to the code and create an action method. Within that action method, you can perform a segue to another view controller, if you wish to transition to an entirely new scene. Otherwise, you can initialize another view and animate it onto the screen.

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.

Custom segue from left to right for form sheets (iPad)

I have some view controllers in a form sheet and right now they all push segue. But I want to make an animation that makes them come from right to left during segue throughout the page. so when I go to the next view controller my segue should start bringing the view controller from the right and the parent view controller starts to move to the left and goes off the screen/fades and the child view controller comes from right and settles at the center of the iPad like how form sheets do. I was wondering if anyone had implemented something like that before? if not, can I get some suggestions in how to do this so that I can get a head start? I have just have a little experience with custom segues, where I could use QuartzCore to animate the view controllers and since they all belong to the same navigation controller I am not sure how can I achieve this fly from right to center and to left animation.
You can create your own full-sized view controller and emulate form sheet's behavior inside it by yourself (with gesture recognizers etc)

Sliding a UIViewController to pop - as in the Readability app

I'm trying to emulate the sliding UIViewController as seen in the Readability app. You can drag a page to the right and it pops the current view off the stack to go back to parent UIViewController with a sliding animation as in the image: the right-most view was on the top and is being dragged right-wards showing the original table on the left.
I've tried a few of the slidingUIViewController solutions such as ECSlidingViewController but they try to emulate the Facebook/Path behaviour of partially sliding a slidingUIViewController on top of another which is not what Readability does.
I've also tried a standard horizontally scrolling UIScrollView but scrolls like the pages are joined at the sides, as opposed to sliding one view over another.
Does anyone know how they did this?
This can be easily accomplished in few steps. I'm not going to write down all the code you need to write in order to do it, but just the steps you need to take. I will use a master-details terminology where the master view is the one from which you want to present a details view and the details view is of course the one at the top of the navigation stack.
When you want to present the detail view:
1) create an instance of the UIViewController that handles the interactions with the detailView. On iOS 5+ you can store this instance in the childrenViewControllers #property on the master's viewController. If you support a lower OS you should store the instance in an ivar.
2) set the detailView's frame to be outside the screen's bounds; add to detailView a shadow for graphical purposes. Finally add the detailView as a subview of the masterView.
3) (optional) add a pan gesture recognizer to the detailView in order to allow the user to swipe the view back and dismiss it.
4) animate the detailView in the screen's bounds. Make sure the interactions with the view below are disabled (be careful not to disable also the interactions with the detailsView!)
When you want to dismiss the detail view:
1) animate the detailView outside the screen's bounds.
2) remove it from it's superview and delete the reference to it's viewController.
3) re-enable the user interaction with the master view.

Resources