SrAn
SrAn

Reputation: 110

iOS : Swift : Right and Left view controller transitions between mutiple view controllers

I have close to 8 view controllers , Each and every view controller has next and back button . How could I do left and right transitions here through swift code . To be more specific on tapping back , previous view controller should slide from left and on tapping next , the next view controller should slide from right.

I am pretty new to iOS development , Any help would be really appreciable.

Thanks In Advance

Upvotes: 0

Views: 469

Answers (1)

Milan Nosáľ
Milan Nosáľ

Reputation: 19767

You should be able to do it using UIPageViewController combining it with its delegate.

However, I'm gonna shamelessly point you to my open source project of custom container with interactive transitions - InteractiveTransitioningContainer. While it aims at allowing to implement an interactive container (as an example it includes a container that allows swiping through viewControllers the way as UIPageViewController works), you can use the SwipeToSlideInteractiveTransitioningContainer class to achieve what you want:

// here you will want your 8 controllers
let vcs = [FirstViewController(), SecondViewController(), ThirdViewController()]

let container = SwipeToSlideInteractiveTransitioningContainer(with: vcs)
// this will disable swiping to navigate between containees
container.interactive = false
self.present(container, animated: true, completion: nil)

// shows the second viewController (index based from 0)
container.show(at: 1, animated: true)

// or move using previous and next convenience methods
let success = container.showNext(animated: true)

You can install it using Cocoa pods. Any feedback welcome :).

Upvotes: 0

Related Questions