Solved

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

Posted on 2014-01-03
10
496 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
10 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
On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

 

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 250 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 250 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Yesterday Apple introduced their revolutionary new iOS 5 operating system that claims to be the ultimate mobile technology interface. One of the biggest innovations of the new operating system is the introduction of the iCloud computing network. Thi…
Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
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…

617 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