File tree Expand file tree Collapse file tree
Example/PuiSegmentedControlExample/Source/Screens/PageView Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -92,8 +92,30 @@ class PageViewController: UIPageViewController {
9292 // Set segmented control property
9393// puiSegmentedControl1.pageViewController = self
9494 puiSegmentedControl2. pageViewController = self
95+ puiSegmentedControl2. delegate = self
9596
9697 }
98+
99+ // MARK: - Helper Functions
100+
101+ fileprivate func navigate( fromSelectedIndex fromIndex: Int , toSelectedIndex toIndex: Int ) {
102+ let viewController = self . pages [ toIndex]
103+
104+ // Check index
105+ if ( fromIndex < toIndex) {
106+ // Then set view controller
107+ self . setViewControllers ( [ viewController] ,
108+ direction: . forward,
109+ animated: true ,
110+ completion: nil )
111+ } else {
112+ // Then set view controller
113+ self . setViewControllers ( [ viewController] ,
114+ direction: . reverse,
115+ animated: true ,
116+ completion: nil )
117+ }
118+ }
97119}
98120
99121extension PageViewController : UIPageViewControllerDataSource {
@@ -116,3 +138,14 @@ extension PageViewController: UIPageViewControllerDataSource {
116138 }
117139}
118140
141+ extension PageViewController : PuiSegmentedControlDelegate {
142+ func segmentedControlTransationBegin( oldValue: Int , newValue: Int ) {
143+ self . navigate ( fromSelectedIndex: oldValue,
144+ toSelectedIndex: newValue)
145+ }
146+
147+ func segmentedControlTransationEnded( oldValue: Int , newValue: Int ) {
148+
149+ }
150+
151+ }
You can’t perform that action at this time.
0 commit comments