Skip to content

Commit a3ebee9

Browse files
committed
Updated example project according to new improvement.
1 parent e7f7808 commit a3ebee9

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Example/PuiSegmentedControlExample/Source/Screens/PageView/PageViewController.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff 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

99121
extension 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+
}

0 commit comments

Comments
 (0)