0

I have a class that subclasses UIPageViewController which contains 4 view controllers.

I am trying to figure out why the below code randomly stops the UIPageViewController from scrolling as I try to stop the bounce effect on the first and on the last controller on the UIPageViewController?

If you keep track of your currentIndex then the below should be sufficient but its a little buggy because there is a random scenario where it stops scrolling altogether and gets stuck on a random view controller.

I think the scrollView.bounces is a little buggy, perhaps I am missing something because most of the time it works fine, if anyone is able to have a solution based on the below it would be great please.

public func scrollViewDidScroll(_ scrollView: UIScrollView) {
    scrollView.bounces = currentIndex == 0 ||
        currentIndex == controllers.count - 1
        ? false 
        : true
}

I managed to get this issue working but the problem I have is trying to figure out how I can scroll half way into the next controller.

UIPageViewController - Detect scrolling halfway into the next view controller to change button color?

Wael
  • 489
  • 6
  • 19
  • Some quick searching seems to show that trying to disable the bouncing tends to be problematic, due to the inherent behavior of a `UIPageViewController`. How many "pages" do you need to show? If it's not many, you may be better off using a standard scroll view. – DonMag Sep 18 '20 at 13:13
  • Hi, thanks for the response, I managed to get it to work after lots of trial and error. The other issue that I have now and is a bit more tricky is explained here https://stackoverflow.com/questions/63902728/uipageviewcontroller-detect-scrolling-halfway-into-the-next-view-controller-to – Wael Sep 19 '20 at 23:32
  • Its 4 view controllers and I am now trying to figure out how to detect scrolling halfway into each controller. – Wael Sep 19 '20 at 23:34
  • It sounds like you're fighting a losing battle trying to override the default behavior of a `UIPageViewController` - particularly when combined with your other question. Since you only have 4 "pages" it seems it would be so much easier to embed them in a standard `UIScrollView` ... and likely much more reliable. – DonMag Sep 20 '20 at 14:13
  • Thank you, I know what you mean but as mentioned I have a solid working solution now for this question to disable the bouncing the scrollView. I am stuck on my other question but I think I am very close. If the other problem in my other question is solved, it will save a lot of work and it will be a much cleaner solution than building a custom ScrollView with StackView. There has to be a way (I hope) if someone could assist that would be great. – Wael Sep 21 '20 at 09:40

0 Answers0