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

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];

Related

Scrollview with button(s) that can appear and disappear on tap

I have created a scrollview, to scroll through an array of images, and I have a button and soon to be 6 more on the screen. Now to make the photo nicer, I would simply like to make the buttons disappear and when tapped on again to appear.
Now I know how to do this with just a regular view with simple isHidden, and how to make it reappear when tapped on, but I am largely confused on how to do it on a scrollview because on a regular view, I just put a button over the whole screen but with the scrollview I can't. Any ideas anyone? Still getting better at this one step at a time, and one question at a time.
Here is a screenshot: http://imgur.com/a/Ll6QO
Use a gesture recognizer on the scrollview.
Add a touch gesture recognizer to toggle the visibility of your buttons. Be sure that the gesture recognizer doesn't cancel touches in view, otherwise you won't be able to scroll.

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.

UISwipeGestureRecognizer over UIButtons

I want swipes to be detected on the lower half of the screen. That part of the screen can have UIButtons as well. I want the swipes to take priority over the buttons (that is, if you swipe over the buttons, the buttons are ignored). But I want the buttons to work if you just tap on them.
I tried placing a transparent view over the buttons with the UISwipeGestureRecognizer attached, but obviously that makes the the buttons not to work as it swallows all touches including taps.
I also tried placing the transparent view behind the buttons, but then the UIButton event handling interferes with the swipe when you swipe over the button.
What's the best way to get this working?
I can think of a solution where the buttons would just be UIImageViews with attached UITapGestureRecognizers so you can then prioritize between the tap recognizers and the swipe recognizers.
But I'd like to keep the buttons as UIButtons to take advantage of the highlighted stuff.
You may try adding the UISwipeGestureRecognizer to the superview of the UIButton.
i resolve same issue.
you just subclass UIButton and override 'touches~' method.
and then connect your customButton to it's parentView via some delegate.

UITableViewCell Editing is very difficult to show

I want my table view cell to show the Delete bar on the right side when the user swipes. However, the table view is in a UIScrollView, and although it is at the far right side, and swiping left does not move the scroll view, the table view cell makes it difficult to edit.
In order to trigger the swipe for editing, I must swipe very fast and in a perfectly horizontal line. The speed required is far more than you can expect users to even want to do, and would not be expected at all from a user's perspective.
I believe the scroll view is the cause, but I cannot be certain. No gesture recognizer is present.
How can I prevent the scroll view from mucking up this experience?
Putting a tableView or webView in a scrollView is not advised, because of the exact problem you are having. Your best bet is to find a way around putting it in a scrollView. Other than modifying your tableView to not be in the scrollView, you might try moving your tableView to the front. [superView bringSubviewToFront:tableView]; hope this helps.
You could try using the gesture recognizer delegate methods for this. I don't have Xcode in front of me, but if you use gestureRecognizer:shouldRequireFailureOfGestureRecognizer: and just fail the scrollView's swiping gesture if the gesture recognized is that of the swiping of the table view cell. Check UIGestureRecognizerDelegate in the docs.

Gesture Recognizer on sub-view outside view's bounds

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.

Resources