iOS Push UIViewController on slide gesture like Sn

2019-04-17 06:30发布

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!

2条回答
相关推荐>>
2楼-- · 2019-04-17 07:00

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.

查看更多
Rolldiameter
3楼-- · 2019-04-17 07:11

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

查看更多
登录 后发表回答