Is it possible to propagate touches from shared application object to a custom view which has not actually received touches and somewhere at the back of the top view? Assume that I can't use my top view to track touches.
It would be difficult - because the top view receives the event first.
You can't just call userInterActionEnabled on the top view, and pass the event down to a lower layer?
Why can you not use the top view to track touches?
If the top view is a subclass then you can use the touchesBegan: method. To pass this onto another subclass you could just use NSNotificationCenter, passing the set of touches as the object. If you're unfamiliar with this you can check out my explanation on this post:
Hittest event problem
Related
I have two overlapping UIViews, and I want both to respond to user touches. At the moment, only the last view that was loaded responds.
How do I get both to respond to touch events?
you could provide a simple protocol which sends all touch events from the first view to the view in the background. So let the view in the background be a delegate of the first view would be a very simple approach.
Otherwise override the method touchesBegan:withEvent: of the view in the front and call the corresponding method of the view in the background.
Cheers,
anka
If you call touchesBegan/Moved/Ended on super after you handle them I think you will achieve what you want.
Finally, since I don't need that both responds at the same time, I made a workaround. I used the methods bringSubViewToFront: and sendSubViewToBack:. This methods made the work.
I have a view containing two subviews(plain UIviews). The parent view recognizes touch events like touchesbegan ,ended, etc. but the sub view is not recognizing the touch event. How to make it recognize the touch event. Specifically i need only sub view to recognize touch events and not parent view. Thanks in advance.
UserInteractionEnabled is set to YES for the views.
There's two ways of dealing with this.
1) Detect the touches in your viewcontroller instead of in a view. You should be able to work out which view contains the point which was touched and from that can decide what to do with the touch (or just throw it away if it wasn't in either view).
2) Create a subclass of UIView and add these to your main view instead of just UIViews. Then you can detect the touches inside your subclass and deal with them accordingly.
Hope that helps.
I need to handle a touch event on my custom uiviewcotroller. I have a sub controller within the view that already handle touch event (it's a plot that handle zooming and scrolling).
I want to make a tabbar disappear when I tap the screen once. Actually it only works (even tought the tabbar doesn fade away but simply is no visible) in the areas in which the subcontrol is not present but I need it to work everywhere still handling the subcontrol events.
Make sure you're calling the superclass's event handler method in your event handler method to continue propagation of the event up the responder chain.
Also make sure the subcontrol's exclusiveTouch property is set to NO.
You might want to have a look at the event handling documentation.
Try to set userInteractionEnabled = NO in subcontrol view.
UPD: Try to add transparent button to subcontrol.
I have a series of UIViews inside a UIScrollView, and the UIViewControllers for those views are not receiving the touch events. If I take the views out of the scroll view then it works.
I have enabled userInteraction on the views but it's still not working!
This must be possible and I'd be really grateful if someone could point me in the right direction!
Thanks,
Mike
Do the views have their own touch handlers, or are you relying on the viewcontroller to get the touches? Depending on how you have set things up, the views may be handling the touches without passing through to the view controller.
I have overcome this issue by overriding the loadView method of the view controller, and setting the view's instance variable to a simple UIView subclass which passes on the touches.
Check what you are returning in scrollview delegate method view for scrollin in scroll view.
As mahboudz mentioned - check if you have any custom handler for touch event. If not, please have one. Its far more relief to do whatever you want to do with your view. Check out Apples sample app from scrollViewSuite. They have tapDetectingImageView delegate. I used the same in my app it worked great! Hope this helps!
You may find this post useful. It's an example of a pretty clean way of intercepting events.
Have touch handlers for view for which you want to receive touch events and that will work.
I have an application with a view containing several subviews. The subviews did not implement any touchesbegins logic. The Superview implemented all touchesbegins logic and manipulated each subview respectively if it was touched (determined by hit testing).
I have since been converting my subviews to layers. My problem now is that if I touch a layer, the hosting view of the superlayer never gets the touchesbegins method called. However if I touch the background, the touchesbegin method fires.
I understood from documentation that layers cannot handle events, if this is so why would it block events to the hosting view?
Thanks for any help, can't get my head around this.
-Corey
I found the problem... I was releasing the sublayers I was creating using [CALayer layer]. Since I didn't have control of them, I shouldn't have been managing them.
CALayers should not block touch events. Is your userInteractionEnabled flag set in the hosting view (sounds like it is, if you're getting SOME touches)? Is it inside a UIScrollView, which may be doing its own touch-handling.
What class is your touchesBegan method in?
I was having a similiar problem because my touchesBegan method was in a UIView subclass.
After moving the method to a UIViewController subclass, my problem was fixed.
Try doing that.