'Swift Problem with UIScrollViewDelegate when paginsIsEnabled

hope everyone is doing good. I have a small problem I can't find any solution. I have a scrollView where I activated isPagingEnabled on it. The scrollview contains multiple images the size of the scrollView.frame.width. My problem is I am trying to find a solution where when the scrollView changes the "page of the picture" I am notified. I tried different methods. I have tried with delegate scrollViewWillEnd and both DidEnd. My method was this

     var pagePositionOfScrollView = Int(scrollView.contentOffset.x/self.scrollView.frame.width)
    var positionActualIncremented = self.positionActual + 1;
    print("positionofscroll view page \(positionOfScrollView)")
    print("position actual \(positionActualIncremented)")
    

I have found that with this implementation there is a problem, the user could drag only to half of it, the page will still scroll to the next one because of isPagingEnabled, but the ending position would be still on the same page and so the pagePositionOfScrollView will be the same. As well isPagingEnabled offers the possibility that if the user slides with velocity the page is changed, but the final scrollView.contentOffset.x still gonna be on the same page, not on the next. Does anybody have any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source