Disable scroll in UIScrollView while multi touching - ios

In my program I use two fingers to pinch (zoom in and out), so sometimes when I want to pinch, app scrolls.
I would like to don't let scrolling in UIScrollView while two or more touches are on screen. How can I achieve that?

Try using UIGestureRecognizer.
In you case you must use a UITapGestureRecognizer, with 2 finger and one tap.
Attach the gesture on the table view.

Related

UIView that expands with a gesture recognizer

I'd need to make a subview expandable as long as the user taps a finger on it and drags it down, and collapsed again to its initial size when the user releases it (is that a Pan gesture?)
I've been looking for an example for this, with no success. Could somebody tell me which should be the best way to implement that?

Limit UITableView panning to 1 finger

I have a scenario where I have two UITableViews as a subview in a main UIView:
UIView (frame = full screen)
+--- UITableView (frame = ~1/3 of the screen)
+--- UITableView (frame = second ~1/3 of the screen)
I want to detect a three finger swipe up on the whole screen area (and also allow the user to pan UITableViews up and down with at least one finger).
I have a UISwipeGestureRecognizer attached to UIView with numberOfTouchesRequired = 3.
I've tried these:
Setting both internal UIPanGestureRecognizers maximumNumberOfTouches to 1 on both UITableViews. To my understanding this should prevent two and three finger pans on the UITableViews but it doesn't. (If I set enabled to NO on these UIPanGestureRecognizers, the touches are correctly passed to the superview. But then the panning/scrolling doesn't work.)
Calling panGestureRecognizer requireGestureRecognizerToFail: with my UISwipeGestureRecognizer on both UITableViews. This works partly, but the panning waits until the swipe hasn't been completed and it feels very clumsy.
Overriding UITableView with setting shouldRecognizeSimultaneouslyWithGestureRecognizer: to return YES, which allows me to detect the three finger swipe. However, the UITableViews beneath pan/scroll up unintentionally.
So how do I limit the number of panning touches to 1 (or 2) and let the three-finger UISwipeGestureRecognizer recognize three finger swipes?
Try overriding canPreventGestureRecognizer: on the top (whole screen) UIPanGestureRecognizer, returning NO for each of the two table view gesture recognizers.
I'd also try overriding canBePreventedByGestureRecognizer: on each of the two table view gesture recognizers to return NO in the case of the topmost UIPanGestureRecognizer.
I've run into a similar situation as yourself quite a while ago and can't remember how I fixed it (the project is long gone), but I seem to remember playing around with the aforementioned methods and eventually getting it to work.

three finger pinch with custom uigesture on uiscrollview

I have a uiscroll that allows pinching, panning and single/doubletap functionality. I would like to add a three finger pinch in/out to trigger something else in my app. Pinch in and do this, pinch out and do that.
The builtin scroll pinch allows 2 fingers by default. How would I add a third? Subclass? Do I have to remove the gestures already on the scrollview?
Create your own custom subclass gesture to handle the three pinch gesture. Act as it's delegate so you can instruct it to be active at the same time as other gestures. Require it to only start when there are 3 touches. You don't need to remove / replace the standard gestures on the scroll view.

How do I pass delayed scroll gestures from a UIButton inside of a UIScrollView?

I have a UIScrollView that contains several UIButtons. Each button is wired up to take an action when the user inputs a touch up event, so they are able to place their finger on the button and it will not be selected until it is raised. Currently, if I made a swipe gesture to scroll the UIScrollView quickly, then the scroll view moves as expected even if the gesture happens directly over a UIButton. HOWEVER, if I hold my finger down too long on a UIButton (about 1 second), the UIScrollView will no longer recognize the gesture and will not be able to scroll until the finger is lifted up.
I am wondering if their is a way to always have the UIScrollView recognize the scroll gesture? Note that this is not an issue if I touch the UiScrollView in a location without a UIButton - it then scrolls as expected.
It may worth a try to let your UIButton respond to UIControlEventTouchDown (maybe with an empty action). I'm not sure if this will work, but conceptually I think it should let the UIButton capture the touch immediately.
(Also make sure you don't enable delaysContentTouches on your scrollview.)
I found the answer to this here: UIScrollview with UIButtons - how to recreate springboard?
Essentially, I had to extend UIScrollView and override touchesShouldCancelInContentView, having it always return YES.

UIScrollView zoomed won't produce swipe

I have a UIScrollView with zooming enabled, and a swipe gesture recognizer setup. When the user is not zoomed, the swipes come through great, but as soon as the user zooms in, the swipe won't come through.
My swipe recognizer is applied to the imageview, and I have tried to apply it to the scroller also. When zoomed, no go.
Is there a secret to getting the swipe while zoomed?
Thanks in advance!
Rob
Where is your swipe gesture recognizer?
Have you tried setting scrollView setCanCancelContentTouches:NO?
Is there a secret to getting the swipe
while zoomed?
Yes, there is. Each UIImageView should be inside its own UIScrollView which in turn are inside of main UIScrollView. No gesture recognizers are needed, just set UIScrollViews options like zoom scales etc and implement UIScrollViewDelegate methods for master UIScrollView.

Resources