IOS: UIScrollView Undo Affects When Using 2 Fingers

I wrote a subclass of UIScrollView that I use to scroll through the UITableView series. See the following diagram:

enter image description here

As you can see, I have several vertical scrollable UITableViews that scroll horizontally inside the parent UIScrollView. All of this works great. However, the application has a number of global gestures. For example, if I scroll in this direction with two fingers, I make the UIView move to another part of the application. but if I make a gesture on top of the scroll view and / or its child table views, they will naturally scroll their contents. This does not look good and causes some layout problems.

I would like to figure out how to disable all scrolling on both UIScrollView and its child UITableViews when the user touches anywhere with two fingers and only two fingers. I tried overriding options for touchBegan, touchsEnded, touchsShouldCancel, etc .... but I can't figure it out completely correctly. Any help is greatly appreciated.

Here is my gesture processing code:

UISwipeGestureRecognizer *twoFingerSwipeUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleTwoFingerSwipe:)]; [twoFingerSwipeUp setNumberOfTouchesRequired:2]; [twoFingerSwipeUp setDirection:UISwipeGestureRecognizerDirectionUp]; [twoFingerSwipeUp setDelegate:self]; // 'self' is the superview of the UIScrollView, which is a UIView. [self addGestureRecognizer:twoFingerSwipeUp]; [twoFingerSwipeUp release]; // ... repeat the above code for up, down, left, right gestures ... - (void)handleTwoFingerSwipe:(UISwipeGestureRecognizer*)swipeGesture { switch ([swipeGesture direction]) { case UISwipeGestureRecognizerDirectionUp: [self changeToView:viewAbove]; break; case UISwipeGestureRecognizerDirectionDown: [self changeToView:viewBelow]; break; case UISwipeGestureRecognizerDirectionRight: [self changeToView:viewToTheRight]; break; case UISwipeGestureRecognizerDirectionLeft: [self changeToView:viewToTheLeft]; break; } } 
+4
source share
5 answers

Try setting panGestureRecognizer.maximumNumberOfTouches = 1 in all types of scroll and table (iOS 5 only).

+1
source

If you use a swipe recognizer to scroll with two fingers, you need the scroll recognizers (including table views - they also scroll), a failure when the two finger recognizer recognizes its gesture.

 [[scrollView panGestureRecognizer] requireGestureRecognizerToFail: twoFingerRecogniser]; 

Iterate the code above for each type of scrolling and table view.

(PS: Recognizer is British English, not spelling.)

Hope this helps. :-)

+1
source

Enter this code: scrollView.minimumZoomScale = 1,0; scrollView.maximumZoomScale = 1.0; scrollView.delegate self];

And here is the scrollViewDelegate method: -

- (UIView *) viewForZoomingInScrollView: (UIScrollView *) aScrollView {return aScrollView;}

0
source

One thing you must do is verify that the gesture is finished before acting on it:

 if (swipeGesture.state == UIGestureRecognizerStateEnded) { // Do your think } 

I know weird things that could happen otherwise.

0
source

Just turn off user interaction in the parent scroll view. You need to subclass UIWindow and override the -sendEvent method: because it is called BEFORE by any recognizing gesture. There, if you find two touches, send a notification. Let the scroll view it and disable user interaction if this happens. And if the touch stops, let him re-enable user interaction.

0
source

Source: https://habr.com/ru/post/1380477/


All Articles