ScrollViewDidEndDecelerating is called for a simple touch.

I implement UIScrollViewDelegate and do a lot of things with it. However, I just found an annoying problem.

I expect scrollViewDidEndDecelerating: to be invoked always after scrollViewWillBeginDecelerating:. However, if I just touch my ScrollView (I actually touch the button inside scrollView), scrollViewDidEndDecelerating: receives the call and scrollViewWillBeginDecelerating: was not called.

So, how can I avoid scrollViewDidEndDecelerating: when I just click the button inside my UIScrollView?

Thanks!

+6
source share
2 answers

Create a BOOL element named buttonPressed or similar and initialize this to false in your init: method.

Set BOOL to true when you press the / s button, and then do the following check:

 -(void)scrollViewDidEndDecelerating: (UIScrollView*)scrollView { if (!buttonPressed) { // resume normal processing } else { // you will need to decide on the best place to reset this variable. buttonPressed = NO; } } 
+1
source

I had the same problem, I fixed it by creating a variable that holds the current page and compares it with the local current page variable if they are equal and then do not continue.

 var currentPage : CGFloat = 0.0 var oldPage : CGFloat = 0.0 func scrollViewDidEndDecelerating(_ scrollView: UIScrollView){ // Test the offset and calculate the current page after scrolling ends let pageWidth:CGFloat = scrollView.frame.width let currentPage:CGFloat = floor((scrollView.contentOffset.x-pageWidth/2)/pageWidth)+1 // Change the indicator print("that the self.currentPage \(self.currentPage) and that the current : \(currentPage)") guard self.currentPage != currentPage else { return } oldPage = self.currentPage self.currentPage = currentPage; print("that the old \(oldPage) and that the current : \(currentPage)") //Do something } 
0
source

Source: https://habr.com/ru/post/902801/


All Articles