I have two nested UIScrollViews: the parent object is limited to horizontal search call, and the child is limited to vertical scrolling. Content is one large view that can be freely moved, but snapped to one of three horizontal sections. The default behavior of nested scroll types allows you to scroll in only one direction at a time, but I wanted to allow simultaneous drag and drop in both directions to keep the feeling of manipulating one large view.
My current solution included highlighting vertical scroll gestures and setting its delegate to my view controller:
for (UIGestureRecognizer *gesture in scrollView.gestureRecognizers) if ([gesture isKindOfClass:[UIPanGestureRecognizer class]]) gesture.delegate = self;
Then I applied the delegate method to simultaneously recognize gestures in swap view mode with a panning gesture of the scroll view:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if (gestureRecognizer.view == scrollView && otherGestureRecognizer.view == pageView) return YES;
This solution basically works, but it will sometimes work as a glitch when I drag it, especially when I quickly move it with the mouse or drag it around the borders of the view. In particular, one of the types of scrolling will temporarily return to where it was started, as if this gesture was canceled, but then it will bounce if I continue to scroll.
I want to know if there is a simpler or more reliable scroll method like this one that I missed, or if there is something that I can do to eliminate the buggy behavior.
iphone uikit uiscrollview
trevorsm
source share