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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is happening because
UIButtonsubviews of theUIScrollView(I assume buttons are added as subviews in your case) are tracking the touches and not the scroll view.UIScrollViewmethodtouchesShouldCancelInContentViewis the key here. According to its description: “The default returned value is YES if view is not aUIControlobject; otherwise, it returnsNO.”, i.e. forUIControlobjects (buttons),UIScrollViewdoes not attempt to cancel touches which prevents scrolling.So, to allow scrolling with buttons:
UIScrollViewpropertycanCancelContentTouchesis set toYES.UIScrollViewand overridetouchesShouldCancelInContentViewto returnYESwhen content view object is aUIButton, like this: