iOS Push UIViewController on slide gesture like Snapchat

烂漫一生 提交于 2019-12-12 09:25:07

问题


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.

  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.



来源:https://stackoverflow.com/questions/26784771/ios-push-uiviewcontroller-on-slide-gesture-like-snapchat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!