Search code examples
iphonetouchtouchesbegan

iPhone Touch View and Sub ImageViews


I have a UIView (mainview), including 50 UIImageViews (image1 .. 50))

(all are set to clickable (UIVIEW and also UIImageViews)

Now to test if one of my images is touched I do in 'touchesbegan':

touch = [[event allTouches] anyObject];
if ([touch view] == image1) { NSLog (@"image1 clicked"); }

But when i test on if my "mainview" (where all images are in) came clicked with:

if ([touch view] == mainview) { NSLog (@"mainview clicked");}

I dont get an confirmation!??

In Short: When mainview alone is clickable i get an OK if clicked But when I activated all images (in the mainview) to be clickable .. I just can check if they are clicked but not anymore my mainview.

view
   mainview
     image1
     image2
     image3
     ..image50

Any ideas?? Thx Chris


Solution

  • That’s because the buttons take the touch. When a touch occurs, it goes up the responder chain until something responds to it—in this case, your buttons. Check out the touch section of the Event Handling Guide for iPhone OS.