views:

389

answers:

2

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 // :)

+1  A: 

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.

mahboudz
Okay, been investigating. My hierarchy is VC with UIImageView subview. Then another subview of that UISubView which is also a subclass of UIImageView. I got events working in the subview to the VC's view. But in the subview to that, nope. Nor in the subclass if it is a subview of the first subview.So, VC.view and a subview to that are getting touch events. Still trying to figure out what could block the other subviews? I even made a dummy class with basically nothing in it except an image and a touch handler. No joy. ?
Spanky
Yup, further testing shows that only the parent view can handle touch events. The subviews aren't able to? I've made sure that nothing was set to exclusiveTouch. I've also looked at resignFirstResponder, not used and nor is beginIgnoringInteractionEvents. And the userInteractionEnabled was set to YES all the way to the top. It's almost like the parent view has become the frontmost view and is blocking everything else from receiving events in the z order? Would there be some XCode setting that might cause this?
Spanky
Okay, this gets even weirder? I just created a whole new view based project. In that project I added a file, a UIImageView. In that I was able to handle touch events. I then created a new class. Again a subclass of UIImageView with basically no other implementation in it. And I added this as a subview to the parent's view. Now the parent can handle touches but the child can't. I remove all touch event handlers from the parent, but leave it enabled and non-exclusive. I then take the code from the parent and paste it in the child. Still no joy.
Spanky
I had a similar issue when my view was totally transparent with an alpha of 0, and touches stopped being sent to me.
mahboudz
A: 

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!

Spanky