ios - Swift: Vertical scroll within horizontal scroll within vertical scroll
问题描述
I'm trying to create scrolling behaviour similar to Instagram's profile page, ie. a vertically scrolling view at the top (eg. name, avatar, etc.), and below that a grid of images that can pan left and right to reveal more sets of images, while also being able to vertically scroll.
For the record, I've read through tons of very similar posts to this, but I haven't found any that address the scrolling issue I bring up below.
This is the setup that I have so far:
Note: the width and height of the green scrollview is equal to that of the red one.
This setup gets me most of the way there, but if you swipe up and let go of the red scrollview it doesn't trigger the green scroll view to scroll. And conversely once the green scrollview has taken up the entire screen there's no way to get back to the red scrollview because its not triggered either.
I've had some success by enabling/disabling the green scrollview when the red scrollview scrolls past the height of the header, but its pretty janky.
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
let translation = scrollView.panGestureRecognizer.translation(in: scrollView.superview)
var isScrollingDown = translation.y > 0
let offset = scrollView.contentOffset.y
if isScrollingDown, offset <= scrollHeight { //scrollHeight is equal to the height of the header cell
greenScrollView.isScrollEnabled = false
}
else if !isScrollingDown, offset >= scrollHeight {
greenScrollView.isScrollEnabled = true
}
}
Is this solution heading in the right direction, or is there a better way to accomplish this that I'm missing?
解决方案
I struggled with this for awhile. I came across this and it has worked very well.
推荐阅读
- python-3.x - 发现一个递归函数对列表中的元素求和很难理解,我想知道是否有人可以很好地向我解释
- postgresql - Azure 分析服务角色与源数据库中的角色冲突?
- oracle - Oracle 使用 RANK 的组的前 N 行运行速度太慢
- vba - MS Access VBA 导出表到文本文件
- javascript - 向 FormData 中的现有键添加键:值
- printf - STM32 CDC_Transmit_FS:为什么在使用 sprintf() 或 strcat() 时会出现 '\x'?
- css - 如何更改 React 组件的大小?
- google-bigquery - 使用 DBT 在 BigQuery 上部署 UDF 函数
- reactjs - 如何在 GatsbyJS 中集成 CSS 框架和内联样式
- shopware - 在 windows 上设置 shopware6 时出现问题