views:

766

answers:

4

I have made sure that all superviews of my customized UIImageView and the UIImageView itself have userInteractionEnabled = YES;

Also in the nib all views and subviews have userInteractionEnabled = YES;

But for some reason, these get never called when I click on the UIImageView:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"check!");
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"other check");
}

I have an UIView that acts as an grouping for some subviews. Can that be a problem?

+1  A: 

It looks like you have a typo there: the correct selector name is 'touchesBegan'. Are you adding this view programatically or through a nib?

Jason
programmatically. Was a typo at SO. Corrected!
Thanks
+1  A: 

touchesBegun should be touchesBegan, but I think that's just a typo?

Depsite that, usually touches not coming through indicates a stressed CPU. Try testing the performance of your app with Instruments.

Kriem
Yes, that was a typo. corrected that!
Thanks
+1  A: 

This is just a guess -- is there a UIScrollView somewhere in the view hierarchy? UIScrollViews don't pass touch events like normal views, you have to subclass it and implement a custom touchesBegan method. You can find information about that here -- it's a problem that sent me scratching my head and Googling for several hours the first time I encountered it.

John Biesnecker
A: 

After a while I figured out the following problem:

I had an UIView that I used to group some UIImageViews together, so that I can move all of them at once by moving that UIView only. I made the UIView 0.01 x 0.01 big while it does not clipsToBounds. As I clicked on subviews that were drawing outside the bounds of their superview, the UIView, no touch events where received on these subviews. I don't know if there were any touch events at all.

So, if you have the same problem, make sure that your touches occur on an area which fits into the superview. In my case, I just made that grouping UIView bigger, making the touch-sensible area bigger. After that, it worked. I now slightly remember that Apple had mentioned that in the documentation somewhere, that subviews may draw outside of their superviews, but touch events will be recognized only if they happen in the rectangle of the superview.

Thanks