I have a scroll view that used to scroll when it didn't have buttons all over it. Now it does, and when dragging the mouse (on simulator) nothing happens (i think because the buttons are being pushed). How can I make this right?
A:
This is happening because UIButton subviews of the UIScrollView (I assume buttons are added as subviews in your case) are tracking the touches and not the scroll view. UIScrollView method touchesShouldCancelInContentView is the key here. According to its description: "The default returned value is YES if view is not a UIControl object; otherwise, it returns NO.", i.e. for UIControl objects (buttons) UIScrollView does not attempt to cancel touches which prevents scrolling.
So, to allow scrolling with buttons:
- Make sure UIScrollView property canCancelContentTouches is set to YES.
- Subclass UIScrollView and override touchesShouldCancelInContentView to return YES when content view object is a UIButton.
Roman K
2010-08-23 17:41:38
thank you for your answer. I changed the scroll having images to simulate buttons (and tracking touches to know when to call a method) I will try your solution though and see how it works. thanks!
DanielaM
2010-08-25 09:07:10