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.
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 think have decent experience working with iPhone development.
as much I know.. I did set up the delegate..
I have from top to botton
UIView --> UIScrollView--> UITextView
I tried everything... to get the event scrollView to fire the scrollViewDidScroll event.
is anything wrong with the structure..
there not much of the code to post here.
what I am trying to do is.. do something when UITextView is scrolled.
Sorry did not respond... Just wanted to share in case anyone need this...
I used delegate methods of parent i.e. UIView for UIScrollView i.e. Child it worked..
It's hard to say without some code or a screenshot. Is the scroll view actually scrolling? If you set it up in Interface Builder, did you change the size of the scroll view's contentSize in code so that it can actually scroll? Maybe the text view is eating the scroll events; did you try setting the text view's delegate to see if it's firing a scrollViewDidScroll event?
I have 4 UIViews inside of a main view controller view. All I need to be able to do is drag the views around the "screen". Is UIScrollView the best option for this, or is there a simpler way?
Apple's Touches sample application contains code that does just this, so you might want to check it out.
UIScrollView should be used for scrolling, not dragging. And the 4 scroll views won't work if they're overlapped so don't even think of using UIScrollView in your case.
A dedicate UIView subclass that overrides -touches*****:withEvent: is needed. See http://github.com/erica/iphone-3.0-cookbook-/tree/master/C08-Gestures/01-Direct%20Manipulation/ for example.
I have a View Controller, and a UIImageView as a subview. That UIImageView also has a subview of that same type.
I have:
self.userInteractionEnabled = YES;
set for each. My touchesEnded code was working. Any idea what would cause this? No touches are even reaching the touches events. I don't understand?
Any help appreciated.
Thanks // :)
Sounds like you've gone all the way up the chain and checked the self.userInteractionEnabled all the way up to the top, right? Ok, now check if any view has exclusiveTouch set to YES.
Also, if you called resignFirstResponder on the parent view, instead of a UIText field, you would relinquish events.
Lastly, beginIgnoringInteractionEvents, can cause this too.
I just found this solution from saimhann2002 who was having a similar problem.
Thanks for the reply. I have been able to fix the problem now. The issue was that I was adding the subview to the MKMapView rather than the view of the ViewController. I don't know why this is an issue. If you do I would be interested to hear. Adding the view as a subview to the view of the ViewController fixed everything, with the view now accepting the touches, even when its colour is UIColor clearColor.
That works!
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.