Drag up Child View Controller with finger and lock after point - ios

I'm trying to implement a smooth transition between two view controllers. What I want to do is have a UIView on the bottom of VC 1. When a user swipes/drags the view upwards, VC 2 will be modally presented. What I want to have happen is as the user drags the view upwards, the view will follow the finger and VC 2 will be dragged onto the screen. As soon as the users finger has gone past a point and then been released, I want it to then lock in place.
I have successfully implemented a UIGestureRecognizer for when a user swipes up on the view. It then presents. There are only two problems with this:
1) It does not transition with the user's finger
2) There are only 4 modal transition styles (Cover Vertical, Flip Horizontal, Cross Dissolve and Partial Curl) - none of which I want to use. I want it to slide up.
I have researched and found this question How to swipe down a UIViewController from another however it hasn't helped as it presents a UIView rather than a UIViewController!
If anyone has any suggestions or example bits of code form someone who has done this before that would be great!
Thank you!

You can use UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate to do the animation which you want to do, these links can be the good starting point ios 7 custom transition
and Custom UIViewController Transitions and watch WWDC 2013 session 218 video Custom Transitions Using View Controllers

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.

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.

iOS Push UIViewController on slide gesture like Snapchat

I have a question about iOS push navigation controllers. I want to push view controller on slide gesture. Just like as in Snapchat application: main view captures images. If you slide from left to right, snapchat messages view smoothly slides (pushes) to main window. If you slide from right to left > contacts view. How to create this kind of navigation? Thanks a lot!
I believe the way that Snapchat does it is through UIViewController containment. Essentially, the main view controller contains a scroll view (paging enabled) with 3 child view controllers (snaps, camera, and contacts). They don't use a navigation controller to present and pop view controllers as you swipe.
See the documentation on view controller containment: https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html
Looking through the snapchat application you probably don't want to do this all in one UINavigationController.
Here is what you need.
UIViewController - This will be your main view. In terms of the snapchat application this is where you would take picutre.
UINavigationController - For the friends list
UINavigationController - For the snapchat (the green window)
You need to setup two segues, both leading from your main controller. Once you have your segues setup I would suggest writing your own transition. Have a look at UIViewControllerContextTransitioning, UIViewControllerTransitioningDelegate, UIviewControllerAnimatedTransitioning.
I am at work, but when I get home I'll throw an example together. However, the above should get you pointed in the right direction.

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+.

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