Nested scrolling of UIScrollViews at the same time

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; // allow simultaneous scrolling of pageView and scrollView return NO; } 

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.

+6
iphone uikit uiscrollview
source share
2 answers

Damaged behavior occurred when views were pulled out of the content area, released, and then dragged / dropped back and forth before the scroll views go back. This can happen, for example, when the preview has been scrolled with a few small clicks. One type of scrolling got confused and tried to slow down (bounce) while dragging, as a result of which it would flinch back and forth between the beginning and the place where it was dragged.

I managed to fix this by changing the nesting of the scroll views (swap view inside the vertical scroll view) and adding a delegate to the UIPanGestureRecognizer swap view, and not in the scroll view gesture. Now it scrolls naturally, as if it were the only kind of scroll that still matched the search call only in the horizontal direction. I don’t think it was intended to view scrolling, to fool its scrolling at the same time, so I’m not sure that the initial behavior of the glitches was the result of an error or simply the result of something unintentional.

+3
source share

He simply fights this and hit the wall with the help of "NSInvalidArgumentException", the reason: "UIScrollView, built into the gesture recognizer, should have a scroll view as its delegate." as indicated by Rythmic Fistman above.

Found a way around it ... first subclass of internal UIScrollView and make it like

Then all you need to do in the implementation:

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } 

Everything seems to be fine.

+2
source share

All Articles