I am creating an ImageViewer similar to the Photos app. I have a PagingScrollView that is the view of a view controller (created in loadView). The pages are UIScrollViews with UIImageView subviews. Everything works hunky dory until I try to 'skip' (set content offset) to an index besides the first one. If I skip to say, image 'i', the image is correctly displayed but if the user performs a single tap gesture the contentOffset resets itself back to display image '0'. The error does not happen with other gestures such as drag and it does not happen with touch if you do another gesture like drag first.
This is my loadView of the ImageViewerController
- (void)loadView
{
//Make the outer spaging scroll view
CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
scrollView.pagingEnabled = YES;
scrollView.backgroundColor = [UIColor blackColor];
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.contentSize = [self contentSizeForPagingScrollView];
scrollView.delegate = self;
self.view = scrollView;
}
This is how I'm trying to set the content offset
#define myView (UIScrollView *)self.view
[myView setContentOffset:[self contentOffsetForIndex:index]];
[..]
- (CGPoint)contentOffsetForIndex:(NSUInteger)index
{
return CGPointMake((index * (self.view.frame.size.width)), 0);
}