Gesture Recognizer on sub-view outside view's bounds - ios

I'm not sure if this is possible, but I have a view that is able to be dragged around the screen via pan gestures. Once the view is selected, little grippers appear on the corners of the view that allow the user to resize the view. The problem is, those grippers go outside the bounds of the view (they still show up, because clipSubviews is off), but gesture recognizers on those grippers are not firing when selecting the part of them that is drawn outside of the view. Making the view bigger to actually hold the grippers would break a lot of already created logic that is based on the size of the view, so that is a last resort for me.
Is there any other way to get gesture recognizers to work on views that are drawn outside of their parent view?

You could try overriding hitTest:withEvent: in a UIView subclass, and return the gripper view.

Related

UIScrollView scrolling using a gesture on the overlaid view

Consider the view hierarchy in the figure below:
OverlayView is simply a control view that has some custom controls on it. It also has multiple tap/swipe gesture recognizers. The ScrollView is the scroll view that needs to be scrolled based on the interactions with OverlayView. The OverlayView has the same frame as that of the ScrollView.
I need a way to add some kind of swipe/pan gesture setup configured for the OverlayView such that I can scroll the underlying ScrollView as if I am interacting with it.
There seems to be two different approaches:
Recognize the gesture on the OverlayView and pass it to ScrollView. But I am unsure what gestures to use and how to make ScrollView interact with them.
Ignore all the touches on the OverlayView unless they are on the controls. Pass these touches to the underlying ScrollView. This seems like the easier approach; but I am not sure how to proceed with this either.
Does anybody have any kind of sample code for some project or a similar exercise they worked on before? If not, any pointers whatsoever?
Option 2 is what I was going to recommend. There is a method you can override called hitTest:withEvent: on UIView.
You return a view from it. So if the touch needs to go through to the scroll view then return the scroll view. Else return self.

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?

How do I allow certain gestures to go through a superview to a view below it?

I have a view with three image views hangin' around. These image views respond to certain gestures. I want to allow a certain gesture (such as a swipe across the screen) to do an action to all of the imageviews (such as, say, delete them all).
The only way I can think of having the swipe gesture be recognized everywhere on the screen is by overlaying a clear superview that looks for swipe gestures. My problem; however, is that I don't know how to let the superview ignore all other gestures so I can still interact with the imageviews below. Is there an easier way to handle this problem?
Try adding the gesture to your view's window rather than the view:
[self.view.window addGestureRecognizer:gesture];

How do I bringToFront a subview when I touch it?

I have a rotating carousel menu made up of 6 UIViews that were added as subViews to self.view. When you rotate the carousel, some subviews are partially behind the subview closest to the user but the problem is that the subview closest to the user may not have been added after the one behind it so when I touch it, the one behind it gets triggered.
My question is, is there a way to programmatically use bringToFront whenever a subview is touched so that it will not matter whether or not it was added first or last to the view.
When you have 2 views responding to touch events and one is in front of the other, the other one will never receive the touch.
Instead of messing around with the event chain (aka subclassing UIView and overriding hitTest…) I'd suggest you reorder the views while spinning the carousel.
The view which appears to be in front should be the topmost view in the view hierarchy.

Resources