In continuation to my question asked here, i want to know if the method to update the UI in viewDidScroll is correct. As i can observe the method is called many times and probably may be the reason why the ui become jittery and unresponsive.
How can i increase the responsiveness of the UI.
The code is as below:
BOOL isScrollingDown = verticalScrollView.contentOffset.y > _previousContentOffsetY;
_previousContentOffsetY = verticalScrollView.contentOffset.y;
CGFloat pageHeight = verticalScrollView.frame.size.height;
int scrollingToPageNum = isScrollingDown ? (ceil((verticalScrollView.contentOffset.y - pageHeight) / pageHeight) + 1) : (floor((verticalScrollView.contentOffset.y - pageHeight) / pageHeight) + 1);
int page = floor((verticalScrollView.contentOffset.y - pageHeight / 2) / pageHeight) + 1;
[self loadPage:(page-1)];
[self loadPage:(page)];
[self loadPage:(page+1)];
/* Unloading the pages not seen in the view is done here*/
if (!(isScrollingDown) && scrollingToPageNum >1) {
[self unloadPages:page-2];
}else {
[self unloadPages:page+2];
}
The lazy loading technique works fine and lot of memory usage is reduced due to it. However the UI is too slow. Also i want to know how to update the UI from a different thread which downloads image from a URL.
TIA,
Praveen
I’m not 100% sure about this so double-check. You have to update the screen in the main thread of the application if you using Apple’s classes like UIScrollView. However, you don’t need to download the images in the same thread. Read Apple’s Concurrency Guide and look at there sample program to figure out how.
In addition it takes longer to draw images that are larger than they need to be. Don’t draw images with more pixel than there is space in the view. For super large images cut them apart so you only draw sections at a time, Apple has sample code for this. When you detect down time draw some images immediately around what’s being displayed to the user. So the user doesn’t see a loading symbol when scrolling around the view. There only so much the pre iPhone 3GS can handle with each iOS release the phone has gotten slower and slower, because it’s doing more stuff you have to manage speed versus fidelity on those phones, drawing a low fidelity image if the user to rapidly moving around then drawing a higher fidelity image if the user stops moving around.
I’ll update this later if I have the time with some links, but those tips above are what worked for me.