开发者

touchesShouldBegin: withEvent: inContentView: not called for UIScrollview

开发者 https://www.devze.com 2023-02-27 01:20 出处:网络
In my UIView i added UIScrollview as subview and in UIScrollview i added UIButtons. Now my problem is that i want to know whether user click on butt开发者_如何学Pythonon or not but touchesbegin of UI

In my UIView i added UIScrollview as subview and in UIScrollview i added UIButtons.

Now my problem is that i want to know whether user click on butt开发者_如何学Pythonon or not but touchesbegin of UIScrollview is not called where as all other delegate methods of scrollview working perfect.

Please let me know if i m doing something wrong.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消