在UIScrollView中滚动期间启用UITableView滚动 [英] Enable UITableView scrolling during a scroll in UIScrollView
问题描述
我在 UIScrollView
表格视图如下:
private(set) lazy var tableView: UITableView = {
let tableView = UITableView(frame: CGRect.zero, style: .plain)
tableView.separatorStyle = .none
tableView.showsVerticalScrollIndicator = false
tableView.rowHeight = 70
tableView.backgroundColor = .blue
tableView.bounces = false
tableView.alwaysBounceVertical = false
tableView.isScrollEnabled = false
return tableView
}()
如您所见,我已经禁用了表格视图中的滚动,因为我希望它与 UIScrollView
中的其余视图一起滚动.我要实现的是,当 UIScrollView
达到一定偏移量时启用tableView的滚动,因此我在 scrollViewDidScroll
委托方法中有了它:
As you see I have disabled the scrolling in the table view because I want it to scroll along with the rest of the views inside the UIScrollView
. What I want to achieve though, is to enable the scrolling of the tableView when the UIScrollView
has reached certain offset, therefore I have that in the scrollViewDidScroll
delegate method:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y >= 160 {
self.view.tableView.isScrollEnabled = true
}
}
以上内容部分起作用.刚刚启用了滚动的 UITableView
不会滚动,除非我将手指从屏幕上移开并再次开始滚动.
The above works partially. The UITableView
that just had it's scrolling enabled doesn't scroll, unless I lift my finger off the screen and start scrolling again.
任何想法如何获得所需的行为?
Any ideas how can I get the desired behaviour ?
推荐答案
重要:您不应在UIScrollView对象中嵌入UIWebView或UITableView对象.如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能会混合在一起并且处理不当.
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behaviour can result because touch events for the two objects can be mixed up and wrongly handled.
这篇关于在UIScrollView中滚动期间启用UITableView滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!