UITableView in UIView in UIScrollView. When scrolling tableview don't scroll scrollview too

99封情书 提交于 2021-02-09 08:49:07

问题


I have a UITableView inside a UIView inside a UIScrollView. Problem: when i scroll/drag the tableview, the scrollview scrolls too.
What i need is for the tableview not to pass the scroll to the scrollview. Also i need to be able to use the scrollview when i scroll it directly. How can i do this? Cheers

enter image description here


回答1:


I fixed it using "hitTest" on the tableview.

 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

If the event originated within the tableview, i disable the parent's scrollview scroll. And, when the tableview's scroll has ended (scrollViewDidEndDragging) i re-enable the parent's scrollview scroll.

This seams to work fine.




回答2:


Set a delegate to your tableview's scrollview (i.e your view controller)

tableView.scrollView.delegate = self;

then use those two calls

– scrollViewDidScroll:
– scrollViewDidEndDragging:willDecelerate:

to disable and re-enable your outside scrollview's scrollEnabled property



来源:https://stackoverflow.com/questions/15233368/uitableview-in-uiview-in-uiscrollview-when-scrolling-tableview-dont-scroll-scr

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