send touch events to another view - ios

I have a UIView ontop of a mapview. Currently the UIView is handling the touchesBegan, touchesMoved and touchesEnded. I need to make it so that the UIView is able to send touch events to the mapView. I have been looking at gesturerecognizers, but so far have had no luck. Has this been done before?, and if so, how can i do this?
my view heiarchy in storyboard
view
mapView
UIView
a little more clarification.
My UIView is used to draw from touch inputs. I have a button that enables and disables the drawing, but the touch events are still bieng handled in the UIView. I want to make it so that when i disable drawing by pressing my button. The user interacts with the mapview instead of the UIView.
I have tried setting userInteractionEnabled = NO in the UIView, but then i can't regain control in that view when the draw button is pressed again.

Related

Zooming on content view inside of scrollview doesn't work

I'm creating a scrollview with content view inside of it. inside of the content view there are buttons.
from this point, i already can zoom and pan on content view. but when the touch happen on a button the scrollview doesn't zoom.
I have just had the same problem and solved it with the following steps :
Create a UIView.
Create a UITapGestureRecognizer
Add the UITapGestureRecognizer to the UIView to handle taps.
Create a UIButton.
Disable User Interaction (isUserInteractionEnabled = false) on the button.
Add the UIButton as a SubView of the UIView.
In the UITapGestureRecognizer tapped selector, handle the UIButton touchesUpInside call.
Add the first UIView into the UIScrollView.
Make sure the UIScrollView delay content touches delaysContentTouches = true
The UIScrollView should be able to now seamlessly zoom and you can respond to your buttons.
You can skip the button altogether if you want and just handle the Tap in the Gesture Recognizer. I had to do it the way above because the buttons were a custom sub classed buttons and had a lot of additional custom rendering and functionality included.

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.

How to get event touch move of UIView when move finger from outside view

I have a UIView custom. In this UIView custom, I have a small UIImageView. When I move finger through it, it will move with my finger. To do that, I use UIPanGestureRecognizer (add this gesture to UIImageView). But when I move finger with begining point not in UIImageView, it will not handle this event.
So, my question is "How to get event touch move of UIView when move finger from outside view ?"
Thanks.
Best approach is create a uiview with necessary size(which is larger than uiimageview). Place the uiimageview inside it. Add gesture recognizer to uiview instead of uiimageview. In the delegate method of geature, move the image view.
There is a "Touch Drag Enter" Event which might be what you are looking for.

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.

ios gesture recognizers in overlapping views

Hi I have a UIView which contains 2 subviews. One is a custom UIView and the other is a MPMoviePlayerController. The MPMoviePlayerController, I assume, has a UITapGestureRecognizer that displays the controls when you tap it. My custom UIView has a UIPanGestureRecognizer. Both views occupy the same coordinate space in it's superview. My custom UIView is layered on top of the MPMoviePlayerController. My problem is that tap events aren't delivered to the MPMoviePlayerController.
What I want is when a drag or pan event is recognized, then don't pass any gesture or touch information along to the MPMoviePlayerController. However, if the drag event is not recognized, such as when the user just taps on the screen, then I want the tap event to be passed to the MPMoviePlayerController.
Thanks.
Add Tap recognized to your own screen too. So you'll have two recognizers. If tap recognizer activate your selector try to tell movie player control this info. It's tap selector is already public, I think.

Resources