iOS:ScrollView 中的图像行
我刚刚开始进行 iOS 开发。我想创建一个包含 2 行图像缩略图作为预览的视图。它会水平滚动。我想知道最好的方法是否是使用 2 个滚动视图或将它们放置在具有 2 行的表格视图中。
I'm just getting started with iOS development. I would like to create a view that would contain 2 rows of image thumbnails as a preview. It would scroll horizontally. I'm wondering if the best approach would be to use 2 scrollviews or place them in a tableview with 2 rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的缩略图和行本质上是静态的,那么最好的选择可能是将缩略图视图直接放入滚动视图中。您可以通过一些任意计算将缩略图子视图布局为两行和尽可能多的列,并避免使用 UITableView 的需要(它非常适合滚动行,但本身不支持列,并且作为工具不是'我认为最适合这项特定的工作)。
如果您确实选择使用 UITableView,我会将其放入单个 UIScrollview...除非您专门寻找两个离散滚动的行,否则我不会使用两个 UIScrollView 来实现此目的。
这是建议一种方法的代码片段。考虑 1) 所有子视图应该具有相同的大小 2) 子视图将根据包含视图的边界自行“网格化”。我为常规 UIView(不是 UIScrollView)编写了此代码片段,但概念是相同的:考虑滚动内容的大小。考虑水平适合多少个子视图,以及垂直适合多少个子视图(因此,如果您想要 2 行,滚动视图高度应该足够高以完全包含单个子视图的高度 * 2):
If your thumbnail images and rows are essentially static, your best bet might be to drop your thumbnail image views directly into your scrollView. You can layout your thumbnail subviews into two rows and as many columns as necessary with some arbitrary calculations and avoid the need to use a UITableView (which works very well for scrolling rows, but doesn't natively support columns, and as a tool isn't imo the best for this particular job).
If you do elect to use a UITableView, I would put it into a single UIScrollview.... Unless you specifically seek two discretely scrolling rows, I wouldn't implement this with two UIScrollViews.
Here is a code snippet that suggests an approach. Consider 1)All subviews should be the same size 2)The subviews will "grid" themselves according to the bounds of the containing view. I wrote this snippet for a regular UIView (not a UIScrollView), but the concept will be the same: Consider size of scrollContent. Consider how many subviews will fit horizontally, and how many will fit vertically (hence, if you want 2 rows, the scroll view height should be just high enough to fully encompass the height of a single subview * 2):