ios gesture recognizers in overlapping views - ios

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.

Related

Movable UIButtons

Scenario:
There is an UIView as a sub view of a UIScrollView and there is a UIImageView as a sub view of the UIView.
Requirement:
When the user touches on the UIImageView I want to add a UIButton as a sub view at that touch point. Any amount of UIButtons could be added (Within the UIImageView frame). These UIButtons should also be movable inside the UIImageView frame.
What I have done
I have sub classed the UIView and I'm detecting touches using methods touchesBegan, touchesMoved, touchesEnded and adding UIButtons. UIButtons are added with UIGestureRecognizers with a method implemented to the pan gesture.
Problem
When I add more than one button the earlier ones becomes non-movable and doesn't even recognise touch up inside.
Thank you all for the help. I ended up doing this https://github.com/Tulakshana/TTaggableView
You should read about Gesture Recognizers:
https://developer.apple.com/library/ios/documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html
http://www.raywenderlich.com/6567/uigesturerecognizer-tutorial-in-ios-5-pinches-pans-and-more
Start with UITapGestureRecognizer for showing UIButtons.

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.

send touch events to another view

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.

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.

Resources