Have implemented a UIScrollView album where in the +2 and -2 positioned SubViews are generated when scrollViewDidEndDragging
is called but adding the Subviews is a costly operation and hence the slide through is not so very smooth. The screen sticks a bit at the end of dragging.
I have even tried delayed calling using NSTimer
or performSelector
but in case the user glides through all images with speed then all the delayed calls are called at once and at times crashes the application.
-(void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
flyNumber = (NSInteger)(imageScrollView.contentOffset.x/imageScrollView.frame.size.width);
[self createM2P2SubView];
//[self performSelector:@selector(createM2P2SubView) withObject:nil afterDelay:0.1];
//[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(createM2P2SubView) userInfo:nil repeats:NO];
NSLog(@"End dragging ...... %d",flyNumber);
}
Please provide a solution in removing that glitch.
Creating views is an expensive operation, but that's essentially what a table view does. It creates views dynamically as new cells appear on the screen, and it reuses the views because they are expensive to create.
Try profiling your code using the Time Profiler and Animation Profiler to find the bottleneck.
Try reusing the views that you are inserting at the +2/-2 offsets to speed things up.
Also a neat trick is to use a UITableView instead of a self-managed UIScrollView. If you need it to be horizontal, then just apply a rotation transform to the table view.
Since you've mentioned the word Album is your title, I'm assuming that there are images that need to be loaded and displayed for each view? Instead of making the image loading synchronous, I'd make it asynchronous and provide an indicator for the Album image loading state using a spinner or something.