You need to implement a scroll view container (e.g. ScrollViewContainer) to handle -hitTest:withEvent:
method:
ScrollViewContainer.h:
@interface BookAlbumScrollViewContainer : UIView {
UIScrollView * theScrollView_;
}
@property (nonatomic, retain) UIScrollView * theScrollView;
@end
ScrollViewContainer.m:
@implementation BookAlbumScrollViewContainer
@synthesize theScrollView = theScrollView_;
//...
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView * child = [super hitTest:point withEvent:event];
if (child == self)
return self.theScrollView;
return child;
}
@end
HERE is a related QA on -hitTest:withEvent:
method.
When you set your scroll view, set it like:
CGFloat yourScrollViewPageWidth = 280.f;
CGRect yourScrollViewFrame = CGRectMake((320.f - yourScrollViewPageWidth) / 2.f, 0.f, yourScrollViewPageWidth, 200.f);
CGRect theScrollViewContainerFrame = CGRectMake(0.f, 0.f, 320.f, 200.f);
// Your scroll view
yourScrollView_ = [[UIScrollView alloc] initWithFrame:yourScrollViewFrame];
//...
[self.view addSubview:bookScrollView_];
// Your scroll view container to handle touches, it should be over |yourScrollView_|
theScrollViewContainer_ = [ScrollViewContainer alloc];
[theScrollViewContainer_ initWithFrame:theScrollViewContainerFrame];
[theScrollViewContainer_ setBookAlbumScrollView:yourScrollView_];
[self.view theScrollViewContainer_];