如何防止 UITableView 内容在水平滚动时被剪切?
我们正在使用 Monotouch 开发特定于 iPad 的应用程序,但我怀疑同样的问题也适用于标准 xcode/cocoa 应用程序。
我们的问题是,我们的 UITableView 必须水平和垂直滚动(请不要建议我们更改设计,因为这不是一个可行的选择)。
通过将 ContentSize 设置为适当的大小(我们将宽度设置为所包含数据的宽度,将高度设置为 UITableView 的高度),我们可以轻松地让 UITableView 以这种方式运行。
然而,这样做有一个令人不快的副作用:当水平滚动时,标题视图和分隔每行的线会被裁剪为框架的大小。有趣的是,内容继续显示,尽管我怀疑这是通过添加到单元格内容视图的子视图显示数据的功能。
我已经尝试了 UITableView 中的几乎所有设置组合(剪切、设置边界、不透明度等),但均无济于事。
我们已经验证,如果我们将 UITableView 嵌入到 UIScrollView 中,这将正常工作,但由于无法重用单元格(这些表视图可能会呈现大量数据)和其他原因,我们不希望采用这种方法(苹果说不要)。
谁能为我们指明正确的方向?我不明白为什么这这么困难。
We are using Monotouch to develop an application that is specific to the iPad, but I suspect the same question applies to standard xcode/cocoa applications.
Our issue is that we have UITableViews that must scroll both horiztonally and vertically (please do not suggest that we change the design as that is not a viable option).
We can easily get the UITableView to behave this way by setting the ContentSize to the appropriate size (we set the width to the width of the contained data and the height to the UITableView's height).
However, there is an unpleasant side-effect to this: the header view and the lines separating each of the rows are is clipped to size of the frame when scrolled horizontally. Interestingly, content continues to be shown, although I suspect that this is a function of displaying our data through subviews added to the cell's contentview.
I have tried just about every combination of settings in the UITableView (clipping, setting bounds, opacity, etc) all to no avail.
We have verified that this will work correctly if we embed the UITableView in a UIScrollView, but we would prefer not to take this approach due to the inability to reuse cells (there could be a lot of data presented by these tableviews) and other reasons (apple says not to).
Can anyone point us in the right direction? I don't understand why this is so difficult.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不保证以下方法一定有效,但您可以尝试以下方法。
要修复标题视图,您需要将标题内容添加到虚拟容器视图中,然后使用此虚拟容器视图作为表标题视图。
现在,您应该将
containerView.clipsToBounds = FALSE
和标题内容的框架设置为所需的宽度(如果您知道的话)。另外,请确保标题内容没有设置自动调整大小掩码。无论containerView发生什么,我们都不希望它改变它的框架。
这背后的想法是tableView将调整containerView框架的大小,但不会改变标题内容框架。通过将剪辑设置为 FALSE,您应该让内容溢出到 containerView 之外...瞧...希望
要修复分隔线,我能想到的唯一解决方案是单元格中您自己的分隔线。然后您可以完全控制其大小。
我用标题视图做了类似的圆顶,并且我设法让内容溢出。
I don't guarantee that the following will work, but you can try the following.
To fix the header view, you will need to add your header content to a dummy containerView and then use this dummy containerView as the table headerView.
Now, you should set
containerView.clipsToBounds = FALSE
and the frame for your header content to the desired width (if you know it).Also, make sure that the header content will have no autoresizing masks set. We don't want it to change its frame no matter what happens to the containerView.
The idea behind this is that the tableView will resize the frame of your containerView, but will leave your header content frames untouched. And by setting the clipping to FALSE, you should get your content to spill outside of the containerView... voila... hopefully
To fix the separator lines, my only solution I can think of is to make your own separator lines in the cells. You can then have full control over its size.
I've dome something similar with the header view, and I managed to get the content to spill.