Avatar of ajitsunny
ajitsunnyFlag for India

asked on 

How to know when UIScrollView is about to stop scrolling in iOS ?

I want to know when UIScrollView is about to stop scrolling in iOS i.e. before calling - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView delegate method.

because here is no such a delegate method or way that can tell scrollViewWillEndDecelerating.So I want to achieve it programatically.  

Please help or guide me.
iOSSwift ProgrammingApple Software

Avatar of undefined
Last Comment
darbid73
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

UIScrollViewDelegate - that's all we have.
There is scrollViewDidEndDecelerating.
I'm not sure, looks like scrollViewWillEndDragging may help.
Avatar of ajitsunny
ajitsunny
Flag of India image

ASKER

I want to be notified when scroll view is about to stop scrolling (few instant(1 or 1/2 second) before stopping not exactly at the time of stopping).

Will scrollViewWillEndDragging will help here ?
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

scrollViewWillEndDragging means end of the dragging.

scrollViewDidEndScrollingAnimation - when the automation ends.

There is contentOffset and visible rectangle properties.
I do not know why you need to know when the scroller is about to stop. Sometimes you may solve your question if you'll ask it a bit different. Looks like now you trying to solve a problem derived from another problem.
Avatar of ajitsunny
ajitsunny
Flag of India image

ASKER

Issue is more on scrolling than dragging  Requirement is like..

I want to initiate a call  to fetch the data from database in secondary thread  to render  UIView .  This data should be available before stopping the UIScrollView. So I can render that data in UI when UIScrollVIew stop.
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

You can work with GUI only in the main thread. You cannot make with a UIView something from any other thread. You can fetch data in a secondary thread, but in order to update a UIView you will have to switch to the main thread. If the last one is busy, you will have to wait.
You know there is a special refresh control. But you can arrange everything as you wish. You can launch the fetch when the scroll stopped dragging and begin scrolling. Let it finish the scroll. The fetch, probably, may happen in a secondary thread and in the end of it switch back to the main thread an update the related UIView object.
For example so:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    [self updateView];
}];

Open in new window

Avatar of ajitsunny
ajitsunny
Flag of India image

ASKER

By going this way UI is waiting for data and flickering after data loaded. So I want to load data only when UI scrollview is about to stop.

 Is there any other way to do it ?
SOLUTION
Avatar of pgnatyuk
pgnatyuk
Flag of Israel image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of darbid73
darbid73
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Apple Software
Apple Software

Programs written for the Apple operating systems are distinguished from software created for other operating systems in that it must be approved by Apple for use on its devices, whether it is from Apple (Final Cut, iWork, Keynote, Logic Pro and GarageBand are popular titles), or is a third party application from Parallels, Nuance, Microsoft and Amazon, among many others.

9K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo