Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1158
  • Last Modified:

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.
0
ajitsunny
Asked:
ajitsunny
  • 4
  • 3
2 Solutions
 
pgnatyukCommented:
UIScrollViewDelegate - that's all we have.
There is scrollViewDidEndDecelerating.
I'm not sure, looks like scrollViewWillEndDragging may help.
0
 
ajitsunnyAuthor Commented:
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
 
pgnatyukCommented:
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
Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

 
ajitsunnyAuthor Commented:
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
 
pgnatyukCommented:
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
 
ajitsunnyAuthor Commented:
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
 
pgnatyukCommented:
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
 
darbid73Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now