views:

611

answers:

1

I tried it with this code in my UIScrollView-subclass:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"he/she touched me");
}

I also made sure that in the initialization of my view, this gets called:

self.userInteractionEnabled = YES;

But when the scroll view doesn't move and i tap on my subview a few times, nothing happens. No log message. I know that the UIScrollView actually waits a moment if the user would like to scroll, but at some point it should give up waiting and fire the event to the subview, right?

Is there something important that I might missed here?

EDIT: Read my answer below, if you have the same problem!

+1  A: 

Instead of deleting my question I think others may be interested in that problem. So, the solution was quiet simple: I just forgot to set

anSuperview.userInteractionEnabled = YES;

So, if your view that must receive a touch event is nested inside any other view, all it's subviews have to be set to userInteractionEnabled = YES;

Thanks
It doesn't sounds right for the view to be settings its superview's userinteractionEnabled. I think you need to look at your design, it's a more general design that the view or better the viewController should be setting its subViews behaviour
Roger Nolan
I have to agree with Roger: it you just want an image that responds to taps, then you'd be better off putting your image view into a custom UIButton (i.e. btn = [UIButton buttonWithType: UIButtonTypeCustom]; [btn setBackgroundImage: image forControlState: UIControlStateNormal];)
Jim Dovey
You're right, the view controller should handle that setup.
Thanks