views:

550

answers:

2

Hi

I have several UIViews and UIImageViews that are loaded inside a UIScrollView. Each "page", except the last one, in the scrollView works fine. The last view doesn't respond to touches, this is always the case no matter if there are 2 or 16 pages. All the pages are build in the same for loop using the same approach.

I have some UIButtons in the views and in the last page I can not get these to respond to touches. It seems that having a UIImageView with a .png with a transparent area on top of a view will block this view from reacting to touches. I think this is maybe what is going on, and some strange/miscalculated offset makes this only show itself in the last page.

Is there some way of debugging the "view stack". e.g. see which layers, UIViews etc. is being rendered to the screen so I can spot the one that is presumably covering my buttons.

In Flash AS3 I seem to remember that a touch event bubbling up the object hierarchy would carry with it, a reference to each view layer underneath the mouse. Is there something like this is the iPhone FrameWork?

Im all out of ways and ideas how to debug this any further. I checked the contentSize of the scrollView, tried coloring the background of each view to see if any of them are covering the buttons and in generally stepped through each line of code. But still no luck :/

Thanks for any suggestion or help given.

+1  A: 

Low-wattage suggestion: You can in fact programmatically walk the view tree from your root, by getting [self subviews], all of which are UIView*s, and then do the same for each of them recursively, etc. You can dump out the frame or other debugging info using NSLog or whatever, and see if any of that information helps you.

Found this; it'll do this for you: http://ramin.firoozye.com/2008/12/11/easy-uiview-debugging-on-the-iphone/

quixoto
Hi Ben thank you!What a fantastic class Ramin wrote!Takes a bit of concentration to piece all the view together from their frames, but it sure beats having to dig through 14 UIView subclasses and write down their frames.It did, however, not confirm my suspicion about a view covering my buttons so the hair pulling continues...
RickiG
+1  A: 

Make sure your UIImageView and any other views that aren't supposed to receive touch events has the userInteractionEnabled set to NO. If they're set to YES, they're intercept touch events within their frames.

lucius
Hi Lucius, thanks for the suggestion, I went through my UIView classes an extra time to make sure user interaction was not enabled on the wrong views. No luck sadly. Just to make sure, are you saying that if I had a UIView containing a completely transparent .png of w:320 and h:480 at the very top of my views, but set it to *userInteractionEnabled:NO* I would be able to catch touch events from a view beneath it?That would be a valued piece of bonus information. Im still pretty new at this frameWork:)
RickiG
I believe so, though I haven't tested it. I know that views with userInteractionEnabled set to NO will not get touch events but the superview will.
lucius
Thanks, think I'll test that out some day. Makes it easier for the designer if he can just design larger UI parts with 320x480 dimensions and leave the transparent areas in there. I could then just "ignore" events from these layers and didn't need to cut and position the layers.
RickiG