The first type:
CGFloat pageWidth = self.scrollView.frame.size.width;
int page = floor((self.scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
Let me give you an example.
The width of a page is 320
Using the results of Method 1
Scenario 1:
Contentoffset is less than 320+160, that is, the left half of the second page, (SELF.SCROLLVIEW.CONTENTOFFSET.X-PAGEWIDTH/2)/ The result of the pagewidth is that the 0.xxxx,floor result is 0 and the result is 1, which returns to the first page
Scenario 2:
Contentoffset greater than 320+160, that is, the right half of the second page, (SELF.SCROLLVIEW.CONTENTOFFSET.X-PAGEWIDTH/2)/ The result of the pagewidth is that the result of the 1.xxxx,floor is 1,page and the result is 2, which will go to the second page
The second Kind
self.scrollView.contentOffset.x/pageWidth
Using the results of Method 2
Self.scrollview.contentoffset.x/pagewidth calculation results are 1.xxx
While page is of type int, the system is automatically forced to transform according to rounding
iOS slides to the first page algorithm based on the offset of the ScrollView slide (different requirements are calculated)