I've been trying to implement swipe navigation between View Controllers in my app using the Swipe Gesture Recognizer and embeded Navigation Controller, but it doesn't look even close to the Snapchat's nav.
What would be the most efficient and appropiate way to implement such functionality?
I'm quite a newbie to Swift and programming really, and I would appreciate every helpful comment.
Paged Scroll View, not a PageViewController in the case of Snapchat.
I had similar requirement, initially implemented with
PageController
, but later I've changed it toUICollectionView
where each cell is fullscreen and scroll is set to horizontal.You need a pageviewcontroller. This was originally for showing tutorials and stuff but you can put view controllers in there as well. There are tons of tutorials out there and essentially you have to apply a little bit of logic to tell the program what view controller to show it next.
This is a pretty advanced example, but it might be of help to you:
https://github.com/cwRichardKim/RKSwipeBetweenViewControllers
You can try using
CATransition
to create the swiping animation. Here is an example of how you can swipe from one view to another:I found some of that code here:How can I implement a swiping/sliding animation between views?
The short version is to use a container view controller with a scrollview inside the controller. You then create separate view controllers for each screen you want in the application, and make those view controllers' parent the container view controller.
A github repo with sample code can be found, here.
I'm not fond of the version given by lbrendanl because it does not use constraints. We can not custom it like we want. Here is the same version but with constraints :
scrollView is an IBOutlet pined to the controller with 4 constraints with a constant to 0 at each sides to the controller's view.
contentView is also an IBOutlet added as subview of scrollView pined to the scrollView with 4 constraints with a constant to 0 at each sides. It also has an equal height constraint and a width equal constraint. The width equal constraint is removed at runtime and only serves to calm down IB. This view represents the contentView of the scrollView.
UPDATE iOS 9
PREVIOUS ANSWER
I've used the lbrendanl's version in the past. Now I prefer this one. Let me know what you think of it.