这是我的问题的屏幕截图:

ios - 如何在iOS中为Swift 3/4移除UIPageViewController的弹跳效果-LMLPHP

最佳答案

首先在UIPageViewController中找到scrollview并添加UIScrollViewDelegate

for view in self.pageViewController!.view.subviews {
        if let subView = view as? UIScrollView {
            subView.delegate = self
            subView.isScrollEnabled = true
            subView.bouncesZoom = false

        }
}

(在ViewController类中扩展UIScrollViewDelegate)

对于方法“scrollViewDidScroll”和“scrollViewWillEndDragging”上的UIScrollViewDelegate,可以添加类似的内容
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)
    }
}

10-06 05:51