问题
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!
回答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
回答2:
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 listUINavigationController
- 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.
来源:https://stackoverflow.com/questions/26784771/ios-push-uiviewcontroller-on-slide-gesture-like-snapchat