Disable UIPageViewController bounce

前端 未结 13 2386
离开以前
离开以前 2020-11-27 04:08

Searched a lot for this one, but couldn\'t find a proper solution yet.

Is it possible to disable the bounce effect of a UIPageViewController and still

13条回答
  •  春和景丽
    2020-11-27 04:33

    In case you wish to disable scrollview on a UIPageViewController subclass entirely, you can use the snippet below. Note that this disables not only the bouncing but the horizontal scrolling of the pages as well.

    In my case I had a UISegmentedControl to switch between the pages in the PageViewController so disabling scrolling vertically was completely fine and working for me. Hope it helps someone else too.

    class MyPageViewController: UIPageViewController {
    
        private lazy var scrollView: UIScrollView = { view.subviews.compactMap({ $0 as? UIScrollView }).first! }()
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            scrollView.isScrollEnabled = false
        }
    }
    

提交回复
热议问题