UIScrollView notifications

I am coding an application that works the same as Apple Weather.app: at the bottom is UIPageControl and UIScrollView in the middle of the screen. In my code, I implemented a method - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView to find out when the user went to a new page. If they go to a new page, I’ll upload the data of neighboring pages to quickly go to the page. (In one example, Apple uses - (void)scrollViewDidScroll:(UIScrollView *)sender , but it causes my application to freeze quickly when loading a new page, so it doesn't work.) This code works very well.

I use scrollRectToVisible: programmatically scroll inside the scroll when the user clicks on the UIPageControl. The problem is that scrollRectToVisible: does not send a notification to UIScrollViewDelegate when scrolling - therefore, the code responsible for loading neighboring pages is never called when using UIPageControl.

Is there a way to get UIScrollView to notify its delegate when it is called by the scrollRectToVisible: method? Or do I need to use threads to prevent my application from freezing?

Thanks!

- Ry

+4
source share
2 answers

What about -scrollViewDidEndScrollingAnimation: :?

If it does not work, try listening to the UITextSelectionDidScroll notification. (Of course, this is undocumented.)

Alternatively, the SDK-safe method measures the time taken to animate and sends a delayed notification to the call site -scrollRectToVisible:

+4
source

Instead, you can add this delegate method:

 - (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView 

The scroll view calls this method at the end of its implementation UIScrollView and setContentOffset: animated: and scrollRectToVisible: animated: methods, but only if animations are requested.

+2
source

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


All Articles