views:

1544

answers:

3

I used the "View-based Application" template in Xcode for an iPhone project and went into the view controller XIB. I changed the view from a basic UIView to a UIScrollView, and now the method - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; never gets called. I have an NSLog statement in there. It gets called just fine when the controller's view is a UIView, so what's different/special about UIScrollViews that you don't receive touch events? How can I respond to a touch event?

TIA.

A: 

I don't have any direct experience here, but I was looking over documentation that might explain this yesterday. I think you'll find that UIScrollView captures touches in order to handle its scrolling. Take a look at delaysContentTouches in the documentation window.

Steven Fisher
+3  A: 

UIScrollView does not pass on all touch events. It does this because it tries to interpret swipe and scroll gestures itself.

Have a look at this thread: http://discussions.apple.com/thread.jspa?messageID=7519817 to learn about UIScrollView and events. The bottom line is that you can handle events in your view's -(void)touchesEnded:(NSSet *)aTouches withEvent:(UIEvent *)anEvent but it's not straight forward.

I have personally seen some funkyness in UIScollView's effect on hit testing sub views.

Roger Nolan
A: 

Just use a custom content subview, then implement touchesEnded:withEvent: in that view. You'll get all the taps you want!

spstanley