Add a UITapGestureRecognizer
to the UIScrollView
, set the delegate
yourself and then this method should give you the index of the tapped image:
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture{
CGPoint touchPoint = [gesture locationInView:<yourScrollView>];
NSUInteger touchedPage = floorf(touchPoint.x / <yourScrollView>.frame.size.width);
if ([<arrayOfImages> count>] > 1) {
touchedPage = touchedPage % ([<arrayOfImages> count] - 1);
}
NSLog(@"Touched page: %d", touchedPage);
//Use touchedPage and push the next view controller here
}
To add the gesture recognizer, add these lines into viewDidLoad
(or you can use the IB):
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[<yourScrollView> addGestureRecognizer:singleTap];