The text of your question doesn't match the title, but for anyone who found their way here because touchesShouldBegin:withEvent:inContentView
isn't getting called on a subclass of UIScrollView
, here's an answer:
The touchesShouldBegin:withEvent:inContentView
method only gets called if the subview being touched responds to touch events. If the user touches a non-interactive subview like a UILabel
, this method doesn't normally get called. You can force it to be called for touches on any given subview by setting that subview's userInteractionEnabled
property to YES.
Also be aware of the state of your scroll view's delaysContentTouches
property. If it's set to YES, then the scroll view won't call touchesShouldBegin:withEvent:inContentView:
until a timer expires, suggesting that the touch is not likely to be a scrolling gesture. If you want touchesShouldBegin:withEvent:inContentView:
to get called immediately, set delaysContentTouches
to NO.
If you're just trying to handle simple taps on the button I suggest you use - (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents (for more info on it look into UIControl) of the UIButton, otherwise my way would be to subclass the UIScrollView, add a delegate for touches and pass them on to it, but it's messy and I wouldn't use this unless extremely custom behavior is needed
精彩评论