Note that there are some explanatory texts on larger screens.

plurals
  1. POSlight pause in scrolling animation (iPad)
    text
    copied!<p>I am relatively new to programming on the iPad and I was trying to put together a simple program. Basically, it's a children's book and I need the functionality of a comic book style (or photo) viewer, where people swipe to change "pages" (or images).</p> <p>Each image is 1024x768. Currently, they are stored as JPGs because of the very large file sizes PNGs seem to produce. For this story, there are 28 pages.</p> <p>I took a look at the PageControl example, implementing a UIScrollView. On initialization, I create a big enough scrollview area. Then as the user scrolls, I load in the previous and next images. Again, just like the example only without implementing the page control at the bottom.</p> <p>The problem I am running into is a very slight pause in the animation when I am flipping. Once the images are loaded or cached, this doesn't happen. Now, I know the photo application doesn't do this and I'm not sure what is causing it.</p> <p>Here is my code for the scrollViewDidScroll method. I keep up with the page number and it will only call the loadPageIntoScrollView when a page has changed - I was thinking that the insane number of calls it was making was causing the slight pause in animation, but it turned out not to be the case. </p> <pre><code>- (void) scrollViewDidScroll: (UIScrollView *) sender { CGFloat pageWidth = scrollView.frame.size.width; int localPage = floor( (scrollView.contentOffset.x - pageWidth / 2 ) / pageWidth ) + 1; if( localPage != currentPage ) { currentPage = localPage; [self loadPageIntoScrollView:localPage - 1]; [self loadPageIntoScrollView:localPage]; [self loadPageIntoScrollView:localPage + 1]; } } // scrollViewDidScroll </code></pre> <p>And here is my <code>loadPageIntoScrollView</code> method. I'm only creating a UIImageView and loading an image into that - I don't see how that could be much "leaner". But somehow it's causing the pause. Again, it's not a HUGE pause, just one of those things you notice and is enough to make the scrolling look like it has a very. very slight hiccup.</p> <p>Thank you in advance for any help you could provide.</p> <pre><code> - (void) loadPageIntoScrollView: (int)page { if( page &lt; 0 || page &gt;= kNumberOfPages ) return; UIImageView *controller = [pages objectAtIndex:page]; NSLog( @"checking pages" ); if( (NSNull *)controller == [NSNull null] ) { UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; NSString *pageName = [[NSString alloc] initWithFormat:@"%d.jpg", page]; controller = [[UIImageView alloc]initWithImage:[UIImage imageNamed:pageName]]; [controller setUserInteractionEnabled:YES]; [controller addGestureRecognizer:singleTap]; [pages replaceObjectAtIndex:page withObject:controller]; [controller release]; } // if controller == null // add the page to the scrollview if( controller.superview == nil ) { NSLog(@"superview was nil, adding page %d", page ); CGRect frame = scrollView.frame; frame.origin.x = frame.size.width * page; frame.origin.y = 0; controller.frame = frame; [scrollView addSubview:controller]; } // if } // loadPageIntoScrollView </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload