Solved

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

Posted on 2014-01-03
10
292 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
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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 19

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When Apple released Swift last year, the aim was to introduce a new programming language for Cocoa and Cocoa Touch that was fast, easy and effective, like the name connotes. Apple succeeded. Swift is designed to couple with Objective-C program…
There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
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 > …
Users will learn how to set proper sequence settings, scale images, paste attributes, add transitions, fades, and music. Open up Final Cut Pro 7 and Create a new Project: Set the Sequence Settings. a) Click File > Easy Setup > Format > Apple ProRe…

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now