tags:

views:

124

answers:

2

I'm new to iphone development, and I wanted to know. exactly what does the UITouch instance method view do

[touch view];

I read up on the documentation and understand that it returns the view that the touch was 'in', but what if there exists a view hierarchy. I had originally assumed it would return the subview that is furthest up 'front'. Does this assumption always hold true?

What is the recommended way of determining if the touch was on a certain view or not.

+1  A: 

Yes, it would return the view that was actually touched (the topmost view) regardless of where the touch is handled.

The only exception I can think of would be if the top-most view was invisible.

Eric Petroelje
Is there an easy way to do figure out the view hierarchy at runtime. Debugger? Print statements?
WillF
Use the 'superview' and 'subviews' properties.
Chris Lundie
I figured out my problem. I was adding a subview to a UIImageView, and I believe by default userInteractionEnabled = NO; so I just set it to set it to YES. This would explain why I wasn't getting the expected result when I called [touch view]; Thanks guys
WillF
A: 

Actually, I believe it gives you where the touch 'started' even though the touch may now be in a different view. Something to keep an in mind if you are watching touchMove and touchEnd events.

Chad