简体   繁体   English

如何在滚动时创建一个覆盖图像的tableView

[英]How create a tableView that covers an image when it is scrolled

I'm trying to develop something like CSStickyHeaderFlowLayout but customized for my table, but I'm not sure how can I achieve this goal. 我正在尝试开发CSStickyHeaderFlowLayout之类的东西,但为我的表定制了它,但是我不确定如何实现此目标。 The idea is 这个想法是

在此处输入图片说明

Someone can give me a hint how achieve this objective? 有人可以给我提示如何实现这个目标?

To add to Vollan's answer, to make the title stay still you could use a view that contains two subviews: the first is the scrollview (with the image and table as Vollan suggests) and then add another view (like a UILabel) for the title. 要增加Vollan的答案,使标题保持静止,您可以使用包含两个子视图的视图:第一个是滚动视图(图像和表格如Vollan所建议),然后为标题添加另一个视图(如UILabel) 。 Thus, while the image and table scroll in the scrollview, the title will stay still. 因此,当图像和表格在滚动视图中滚动时,标题将保持静止。

Best solution would be to wrap everything inside an UIScrollView. 最好的解决方案是将所有内容包装在UIScrollView中。 That will allow you to scroll to bottom of the screen and then only scroll the tableview. 那将允许您滚动到屏幕底部,然后仅滚动tableview。 That way it will appear like the tableview will overlay the image. 这样一来,它看起来就像表格视图将覆盖图像一样。

While using a tableview within a scrollview would likely work, your tableview would have to always be it's full size (without some annoying constant re-sizing), so you'll lose the value of the enqueuing/dequeueing that makes tableViews work so well. 虽然在滚动视图中使用表视图可能会起作用,但您的表视图必须始终是全尺寸的(没有一些烦人的常量重新调整大小),因此您将失去使表视图正常工作的排队/出队的价值。

The CSStickyHeaderFlowLayout has example pretty similar to what you want to do, did you look at their examples? CSStickyHeaderFlowLayout的示例与您想要的示例非常相似,您是否看过它们的示例? You may be able to play with it and get it to do what you want If your problem is simply having a constant title, you can just add a view above the table or use the NavBar and adjust the contentInsets 您可能可以使用它并使它做您想做的事情如果您的问题只是拥有一个不变的标题,则只需在表上方添加一个视图或使用NavBar并调整contentInsets

You might also consider using a collectionView instead. 您可能还会考虑使用collectionView。 It's much more flexible as far as layout goes. 就布局而言,它要灵活得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM