I have two nested UIScrollViews: the parent limited to horizontal paging and the child limited to vertical scrolling. The content is one large view that can be freely dragged around, but snaps to one of three horizontal sections. The default behavior of the nested scroll views is to only allow scrolling in one direction at a time, but I wanted to allow simultaneous dragging in both direction to maintain the feeling of manipulating a single large view.
My present solution involved isolating the vertical scroll view's gesture and setting its delegate to my view controller:
for (UIGestureRecognizer *gesture in scrollView.gestureRecognizers)
if ([gesture isKindOfClass:[UIPanGestureRecognizer class]])
gesture.delegate = self;
Then, I implemented the delegate method to allow the gestures of the paging view to recognize simultaneously with the pan gesture of the scroll view:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if (gestureRecognizer.view == scrollView && otherGestureRecognizer.view == pageView)
return YES; // allow simultaneous scrolling of pageView and scrollView
return NO;
}
This solution mostly works, but it will occasionally act glitchy when I drag the view around, particularly when I move it around quickly with mouse or drag it around past the view bounds. Specifically, one of the scroll views will temporarily jump back to where it started as if that gesture had been canceled, but then it will jump back if I keep scrolling.
What I want to know is if there is a simpler or more reliable method to achieve scrolling like this that I've overlooked, or if there's anything that I can do to eliminate the glitchy behavior.