views:

30

answers:

1

Wondering if anyone has written or come across a good way to log to the console the view that a touch occurred in. I know touchesEnded: can be implemented, but my problem is that something mysterious is blocking touches on my views and I don't know what it is. I would just like to know what is intercepting the touches.

I would like to log to the console:

"Touch occurred in view: nameOfSomeUIView"

A: 

Hi,

Each UITouch object has a view property described as "The view in which the touch initially occurred." You can subclass UIWindow and override the sendEvent method. In your implementation of sendEvent you can call [super sendEvent: event] and after that inspect the view properties of all the touches that belong to the event.

As a general tip: Check the hitTest method of your views if your UITouches do not behave as expected. You can override this method to see which view should receive touches.

Felix
I have subclassed UIWindow and used the subclass type in the App Delegate. I implemented - (void)sendEvent:(UIEvent *)event in the subclass, but it is never getting called.
sol
Actually scratch that, I'm getting sendEvent now. Can you suggest how to find which view is being touched?
sol
Figured out how to pull the touch out of the UIEvent. I can get the memory address of the view being touched. Would be nice if I could get it's name.
sol
You could use the "tag" property of your views to identify them. Otherwise add a name property to your subclass "MyView" of "UIView" and if on of the "touch.view" objects is an instance of "MyView" log it's name property. Hope this helps.
Felix