0

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!

Jacob Jones
  • 501
  • 2
  • 6
  • 22
  • Have you looked into NavigationViewControllers? They use a similar animation when animating new viewControllers using the presentViewController method. – joels Nov 06 '14 at 17:01
  • Is it a third party library? – Jacob Jones Nov 06 '14 at 17:14
  • No! You can make a UINavigationController and use its methods without having to import any additional frameworks. :) – joels Nov 06 '14 at 17:17
  • Oh! UINavigationController! :D. Yes, I believe, that I should use UINavigationController. But how to navigate between navigation controllers on swipe gesture? – Jacob Jones Nov 06 '14 at 17:24
  • Oh sorry! Well, to navigate using a swipe, you'll first need to add a swipeGestureRecognizer to the view on the UiNavigationController. I 'believe' (I could be wrong), but when you recognize a left/right swipe, you can call on the left or right navigationItem methods and present your desired viewController. – joels Nov 06 '14 at 17:31
  • Hmmm... I haven't found that way yet... Can you post example piece of code please? – Jacob Jones Nov 06 '14 at 18:37

2 Answers2

1

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

richy
  • 2,716
  • 1
  • 33
  • 42
Aaron Wojnowski
  • 6,352
  • 5
  • 29
  • 46
  • But snaps and contacts has navigation bar and back button. And, actually acts as like as pushed UIViewControllers... – Jacob Jones Nov 06 '14 at 17:15
  • 1
    The back buttons just alter the `contentOffset` of the scroll view. They don't actually move you anywhere in the navigation stack. – Aaron Wojnowski Nov 06 '14 at 18:17
  • Why is it better way than to create swipe based navigation controller? – Jacob Jones Nov 06 '14 at 18:47
  • The nature of their application would not be appropriate for a navigation controller. When you leave friends, you aren't done with the view since you could go back to it at another time. You just navigate away from it. Therefore a pop is inappropriate. Not to mention altering a navigation controller to do what you suggest would be very, very difficult. – Aaron Wojnowski Nov 06 '14 at 19:59
1

Looking through the snapchat application you probably don't want to do this all in one UINavigationController.

Here is what you need.

  1. UIViewController - This will be your main view. In terms of the snapchat application this is where you would take picutre.
  2. UINavigationController - For the friends list
  3. 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.

Freddy
  • 2,249
  • 1
  • 22
  • 31
  • As far as I thought at first, I thought that there is: SnapchatCameraViewController, SnapchatSnapsViewController, SnapchatContactsViewController. SnapchatCameraViewController < swipe < SnapchatSnapsViewController AND SnapchatCameraViewController > swipe > SnapchatContactsViewController – Jacob Jones Nov 06 '14 at 17:20