Solved

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

Posted on 2014-01-03
10
261 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Macbook Hard Drive Issue 23 98
iPhone Mail: manually checking ALL email 3 25
iPhone Camera Apps - Raw images? 2 28
iOS and RAM 7 26
Steve Jobs once said that Blu-ray is "a bag of hurt". As Macs users well known, things haven’t settled down (at least not from Apple’s perspective). Several years after that comment, Mac OS X still doesn’t support Blu-ray playback, nor has any Mac s…
A lot of new and distinct gadgets are making their appearance every other day. The latest gadget that has wooed the attention of all gadget lovers and non gadget lovers alike is the Smartwatch. This tiny gadget is capable of offering live access to …
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…

747 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

13 Experts available now in Live!

Get 1:1 Help Now