?
Solved

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

Posted on 2014-01-03
10
Medium Priority
?
780 Views
Last Modified: 2016-06-08
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.
0
Comment
Question by:ajitsunny
  • 4
  • 3
8 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 39756201
UIScrollViewDelegate - that's all we have.
There is scrollViewDidEndDecelerating.
I'm not sure, looks like scrollViewWillEndDragging may help.
0
 

Author Comment

by:ajitsunny
ID: 39756356
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 ?
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 39757041
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.
0
[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 

Author Comment

by:ajitsunny
ID: 39758550
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.
0
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 39758599
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

0
 

Author Comment

by:ajitsunny
ID: 39758940
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 ?
0
 
LVL 33

Assisted Solution

by:pgnatyuk
pgnatyuk earned 1000 total points
ID: 39758995
Anyway you cannot update GUI from another thread. Only from the main thread. That's simply a fact.

Try to preload the data. For example, the content offset in the scroll view is 1000 and you know that next touch will lead to the data fetching, so start to fetch data now.

The official answer probably should be: make the data loading as fast as possible, Xcode instruments will help you to profile your app and find the most time spending places in your code.
0
 
LVL 20

Accepted Solution

by:
darbid73 earned 1000 total points
ID: 40074282
Just reading your question and comments it sounds like you are trying to reinvent the wheel.  iOS provides a number of CollectionViews to satisfy exactly your needs.  The two we all know the best are UITableView and UICollectionView.  Both handle exactly your situation of lazy loading of data and you will find many examples of this.  

I dont usually link to Google but there are just so many options here.  You will find both questions and blogs on this.

Basically these views handle scrolling and making sure that only just enough information is "fetched" based on how the user scrolls and you have to do very little work to make this happen.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

     Intro      In this article, I will show you how to parse a JSON in Swift using an open source library called SwiftyJSON (https://github.com/SwiftyJSON/SwiftyJSON). If you haven't heard of a JSON before, it stands for JavaScript Object Notation…
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
Users will learn how resize a batch of photos from a single command in Photoshop via Photoshop's Image Processor. Open up an Image you'd like to resize in Adobe Photoshop: Adjust the image size according to your preferences. Image > Adjustments > …
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question