UIButton not responding to touches - no scroll view - ios

This is my view hierarchy. Send arrow is not responding immediately on the device, it takes multiple touches to trigger the action. But on the simulator, it works perfectly fine. There are no explicit gesture recognisers added in any view, no scroll views and the super view does not delay touch events or anything that I'e noticed in similar questions.
EDIT: Action added through the storyboard. I tried for all touch events and for all of them, the touch is non responsive. Only after a few touches, the action is triggered.
Here's the view debug hierarchy.
Is there any reason why the touch trigger is blocked here? I'm stymied. Help?!

Google Maps override the touches of Views.
Use this way to add your Views.
[self.view insertSubview:viewToAdd aboveSubview:mapView_];
If You adding Views for XIB then Send you map view to back.
[mapView_ sendSubviewToBack:YourView];

Related

Disable userinteraction or touches event in UIView but still enable for subview

I have UIView like this.
I need to put my finger on that view and drag along on those button just like playing piano. Problem is that if initial touch point is on the main view and if I drag along, touches event for main view is triggered and my buttons touch events are not triggered.
As a result, I put this.
[self setUserInteractionEnabled:NO];
Problem is that it has disabled my buttons and other subviews. I want to totally ignore touch event, user interaction from main view but allow for all those subview. How shall I do?
You can set up a notification event for keyboardWillShow and inside the target function set [self setUserInteractionEnabled:NO]; for the superView and when keyboardWillHide notification re-enable it. For hiding the keyboard you could use the GO Button or to dismiss the keyboard add an invisible UIButton to the remaining part of the Screen when the keyboardWillShow event is called and use it to resign first responder.
Hope this helps.
You should create a subclass of UIView for your main view. It should overwrite - hitTest:withEvent: returning always the nearest view for a key.
An alternative solution without inheritance is giving all keys an invisible border such that their views cover the complete main view but never returning the main view.

Present view controller while touching

I want to implement a hold-to-preview button that brings up a view containing an AVPlayerLayer, which plays as long as the touch doesn't end. The video player is contained in a different view controller, and I am hoping to be able to use presentViewController:animated: when presenting it, and not just add it as a subview and child view controller.
My question is about how to deal with the touch event. I see two possible ways:
I try to transfer the active touch down event to the presented view controller (not sure if even possible), or
I try to keep the original view controller's gesture recognizer active, and then let the video view controller know when it's time to dismiss itself. I'm hoping this could be achieved either by just setting the presented view controller's userInteractionEnabled to false, or perhaps using a UIViewControllerTransitioningDelegate to present it, and then just skip calling completeTransition: or something similar (I believe touches don't register on the new view until you complete the animation, but please correct me if I'm wrong).
My question is about how to deal with the touch event.
Touches are always associated with the view that they start in. You can't transfer the touch to a different view. I've never tried it, but the options I think you should explore first are:
Use view controller containment. Make your preview view controller a child view controller of the one where the touch originates. That way the parent and its view hierarchy never go away, although they could be covered up.
Attach the gesture recognizer to the window. A window is a view, and should be able to have gesture recognizers. You could make the gesture recognizer's target the app delegate or some other object that will always be around, and have the delegate post a notification when the recognizer is triggered. Again, I haven't tried this, but it seems like it should work.

Forwarding touches to UINavigationController Interactive Pop Gesture Not completely Working

I'm trying to enable interactive pop gesture recogniser on my keyboard's accessory view. It does not work by default.
I passed an interactive pop gesture recogniser reference to my accessory view in order to forward its touch events to the recogniser
It particularly works: the navigation bar's title gets changed and the background of the accessory view reveals the previous view controller's view as if the transition did start. But the top view itself remains in place even if the gesture recogniser completes tracking.
I also tried to forward touch events to the navigation controller itself, to its view, to its top view controller and to their window. Nothing changed even after forwarding to all of them simultaneously
Any ideas what is missing?
It looks like it is not possible to reuse touch event instances in the responder chain. Once the sendEvent: on UIWindow is called, there is already a certain view owning the touch, so there is no cense in forwarding the UIEvent instances to other views or their gesture recognisers.
However, the owning view can forward events to its nextResponder()s (e.g.: one of the gesture recognisers attached to this view or to one of the subviews of the view)
The only chance to forward touches to another view (from another view hierarchy) or another view's gesture recognisers is before the UITouch object creation: i.e. on the UIWindow level during the hitTest:withEvent: method invocation, which calls the pointInside:withEvent: method
Anyway I'm not sure whether it is possible to forward touches from one UIWindow to another. Will update the answer later
http://www.russbishop.net/uitouchtypestylus?utm_campaign=iOS%2BDev%2BWeekly&utm_medium=email&utm_source=iOS_Dev_Weekly_Issue_225
http://smnh.me/hit-testing-in-ios/

In iOS 8 what is the correct way to add a gesture recognizer on everything in my view controller except a button, without adding an additional button?

I have a button that when tapped shows the button text. In iOS 8 what is the correct way to implement a gesture recognizer to my view controller, so that when anything else is tapped besides that button will remove that text. I would like to avoid adding an additional button because I have multiple buttons that I would like to apply this gesture recognizer to in addition.
You could try using touchesBegan - that would capture touches elsewhere, however if you have another UI element in the view that interacts with touch I believe touchesBegan will not be called in that case as the UI element will not pass the touch event on.
Implement it and pop some logging in there and see what's going on. Could be the solution you're after.

How to detect touch on screen in custom UIView?

I want to watch in my UIView subclass for user touches on the screen. Especially there are some additional conditions:
the touch should not be catch by my view (for example, if user taps some button or scrolls something that action should be accepted)
there can be multiple views which are watching for touch and they should not conflict with each other
the approach should be as general as possible (so we can catch taps on tabbar or navigation buttons)
I can suppose to add specific fullscreen view with customized hitTest: method. This view has interface to add/remove delegates for watching for touches. But this method is "hard" in coding terms and I would like to find more elegant and simpler solution.
you can write touchesBegan in that UIView subclass.
Because if it had any subview like button or scrollView, they would be first responders ,and touches on scrollView wont fire touchesBegan of your UIView subclass.
And it wont conflict with other touch listeners unless the listener subView is explicitly passing that touch to your Subclass.

Resources