Here is the screenshot of my issue:
Asked
Active
Viewed 2,037 times
2 Answers
4
First find scrollview inside your UIPageViewController and add UIScrollViewDelegate
for view in self.pageViewController!.view.subviews {
if let subView = view as? UIScrollView {
subView.delegate = self
subView.isScrollEnabled = true
subView.bouncesZoom = false
}
}
(Extends UIScrollViewDelegate in your ViewController class)
For UIScrollViewDelegate on method "scrollViewDidScroll" and "scrollViewWillEndDragging" you can add something like this
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if(currentIndex == 0 && scrollView.contentOffset.x < scrollView.bounds.size.width){
scrollView.contentOffset = CGPoint(x:scrollView.bounds.size.width, y:0.0)
}else if(currentIndex == 2 && scrollView.contentOffset.x > scrollView.bounds.size.width) {
scrollView.contentOffset = CGPoint(x:scrollView.bounds.size.width, y:0.0)
}
}
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if(currentIndex == 0 && scrollView.contentOffset.x < scrollView.bounds.size.width){
scrollView.contentOffset = CGPoint(x:scrollView.bounds.size.width, y:0.0)
}else if(currentIndex == 2 && scrollView.contentOffset.x > scrollView.bounds.size.width) {
scrollView.contentOffset = CGPoint(x:scrollView.bounds.size.width, y:0.0)
}
}

Rafiqul Hasan
- 3,324
- 4
- 20
- 28
1
I've done this like following code.
func scrollViewDidScroll(scrollView: UIScrollView) {
if currentIndex == 0 && scrollView.contentOffset.x < scrollView.bounds.size.width {
scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
} else if currentIndex == totalViewControllers - 1 && scrollView.contentOffset.x > scrollView.bounds.size.width {
scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
}
}
func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
if currentIndex == 0 && scrollView.contentOffset.x < scrollView.bounds.size.width {
scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
} else if currentIndex == totalViewControllers - 1 && scrollView.contentOffset.x > scrollView.bounds.size.width {
scrollView.contentOffset = CGPoint(x: scrollView.bounds.size.width, y: 0)
}
}

Aleem
- 3,173
- 5
- 33
- 71
-
Thanks for your answer! – Jamil Hasnine Tamim Mar 12 '18 at 07:14