Prevent subview from scrolling in a UIScrollView

戏子无情 提交于 2020-01-14 12:40:14

问题


I have a UIScrollView subclass with a certain subview I'd like to prevent from scrolling (while all the other subviews scroll as normal).

The closest example to this I can think of is UITableView's "index strip" on the right side (look in the Contacts app to see an example). I am guessing this is a subview of the table (scrollview) but it does not move as the user scrolls.

I can't seem to make my subview stay put! How can I accomplish this?


回答1:


The trick is to adjust the frame of the "non-scrollable" subview inside -layoutSubviews.




回答2:


Add the view that you want not to move as a sibling view of the scroll view on top of the scroll view instead of as a subview.




回答3:


You can set it's property called userInteractionEnabled to NO



来源:https://stackoverflow.com/questions/3011076/prevent-subview-from-scrolling-in-a-uiscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!