iOS - Detect when gesture ends outside of the origin view - ios

I have a UIView organized with two columns and each column have it own UIViewController. I need to hide my left view when the right view receive a swipe gesture with the left direction.
I added a UISwipeGestureRecognizer to the right view and the code works when the gestures begins and ends in the right view. However, if my gestures begins in the right view and ends in the left view my event is not triggered.
Anyone know how I can handle this?

Related

How to make a UIScrollView, some UIButtons and UIPanGestureRecognizer work together?

I got a scroll view with a bunch of buttons, which I want to both touch and drag.
To choose if it's a touch or a drag (not drag of the scroll view, "physically" dragging the button), I check the pan gesture recognizer of the button to see how far away the drag would be, if it's over a threshold I snap the button into drag mode and, removing it from the scroll view and adding it to my view controller's view (at the same location, so looks like it's in the same place).
This all works kinda smooth, except when I want to scroll and the pan fires at the same time. I need a way for the pan gesture recognizer to choose, based on velocity, if the scroll view should scroll or the button should be dragged.
The question: Is there a way for a UIPanGestureRecognizer to tell a UIScrollView to continue scrolling and cancel itself?

UIGestureRecognizer Pass-Though View

How do I create a view that allows some gestures to "pass-through", basically I have 2 views the top view completely covers the other, I need the top view to handle left/right swipes and the one below has a UIScrollView that needs to respond to up/down swipes, tap and long press, so essentially pass the events down the chain.
Is this the wrong approach?

Recognize a touch for a UIView that is only created at the moment that touch occurs

I created a "slide view" (a UIView subclass) which animates on screen by dragging it up. The animation and everything else related to the animation works perfectly fine. This question targets only the very first touch on the screen when the slide view itself will be initialized:
The slide view itself uses the UIPanGestureRecognizerto recognize touches. The thing is, my slide view will be initialized only at the time when the user touches down a UIButton. Parts of the slide view are initially locates on that button, so that when the user touches that button, the touch is also located inside the slide view's frame.
I only want to create the view at the time the touch occurs, because the view is pretty heavy. I don't want to waste resources cause often the button is not even used.
How can I make the slide view recognize that first touch that also initializes (and adds it as a subview to super) the slide view itself?
You can check this out for more details:
Gestures
Well and you can add both gesture pan as well as tap gesture. It will definitely work as tap is not the first action of the pan gesture. So no need to wait for tap gesture to fail.
In short you can add both gestures and handle them simply.

ios move touch event between two uiscrollview

I'm building an iOS layout which consists of a UITableView and a UIScrollView. The UIScrollView is inside a table cell of the UITableView and can be scrolled both horizontally and vertically. The diagram below shows this situation. If the user begins scrolling down/up on the UIScrollView the scrolling event should trigger setContentOffset of the table view, and not setContentOffset for the scroll view while the top of the scroll view will be on the dotted line (it's constant height). Then a scrolling touch event should trigger setContentOffset for the scroll view, not for the table view.
In another case: When the user starts scrolling on the table view, it should trigger setContentOffset for the table view, until the scroll view reaches the dotted line. Then the scroll view should handle setContentOffset.
My problem is how to transfer touch events between the table view and the scroll view during one sliding action.
This sounds like one of those cases where you want something quite specific and custom. So trying to do something clever with the gesture recognizers won't be enough.
The main problem is that the ways you can control gesture recognizers such as with gestureRecognizer:shouldReceiveTouch: and gestureRecognizerShouldBegin: only affect the start of the gesture (or for new touches, not ongoing ones), but you want a single ongoing gesture to transition between controlling each view. So for this reason I think you will need to place a large transparent view over your entire screen with a pan gesture recognizer on it and in your handlePan method decide which view you want to adjust and then call setContentOffset directly on that view. You can use the translation of the pan recognizer and the existing content offset to calculate the new one. I know this isn't very elegant, but I can't think of another way to achieve the effect you want.
I'm not sure if this is going to work, but you could try doing something like this:
Option
self.scrollView.panGestureRecognizer = self.tableView.panGestureRecognizer;
Option
[self.scrollView addGestureRecognizer:self.tableView.panGestureRecognizer];
Option
[self.tableView.panGestureRecognizer requireGestureRecognizerToFail:self.scrollView.panGestureRecognizer];

moving a view under finger

I have a view-chain; the first view is in the second, the second is in the third and so on.
I want to move the top most view under my finger and I did some logics to handle this in touchesBegan:touchesMoved:...
The problem is that each view has different gestures and if I try to move the top most view, the views behind it also respond to the moving. Is there any way to disable the gesture except the top most view when I am trying to move it?
Also I do not want the top most view to go outside the border of its immediate parent view, and I did some logics in the touchesMoved: to reset the center or the top-most view. The effect is not good as this approach allows the view to go outside, but will move it back once it went out.
How about just creating and turning on a disable flag at the bottom views while adding the top most view to it's parent view, if you don't want the bottom views to respond to their own gesture recognisers?

Resources