Tableview 滚动反弹并隐藏底部单元格
我有一个显示在导航控制器下的视图。该视图在顶部包含一个子视图,在底部包含一个表视图。根据数据,表中的行可能超出可见高度。当我的行位于最后一个可见行下方时,如果我向上滚动视图,它会弹回来,不会停留在那里。有办法让它留下来吗? 我尝试将父视图设为滚动视图,但这没有帮助。我的观点来自 XIB。
I have a view that is shown under a navigation controller. The view contains one subview at the top portion and a table view at the bottom. The table might have rows that extend beyond the visible height based on data. When I have rows that are below the last visible row, if I scroll the view up, it bounces back, it does not stay there. Is there a way to make it stay?
I tried making the parent view a scroll view and that did not help. My view is from a XIB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来你的 UITableView 的大小比 iPhone 屏幕上的可用区域稍大。这可能是因为视图没有考虑导航栏的大小。作为测试,进入 Interface Builder 并将 UITableView 做得更小,比如一半大小,这样您就可以清楚地看到顶部和底部。看看你是否还有同样的弹跳。
如果大小正确,UITableView 不需要 UIScrollView 即可按预期运行。事实上,我现在能想到的原因很少(除了水平滚动的原因),你会想要在 UIScrollView 中使用 UITableView。
Sounds like the size of your UITableView is slightly larger than the area available on the iPhone screen. This might be because the view didn't take into account the size of hte navigation bar. As a test, go into Interface Builder and make the UITableView much smaller, say half the size, so you can clearly see the top and bottom. See if you still have the same bouncing.
If the sizes are correct, UITableView does not need a UIScrollView to function as expected. In fact, there would be few reasons, that I can think of right now (other than horizontal scroll ones), that you'd want a UITableView inside a UIScrollView.
在顶级视图控制器的“模拟指标”设置中,将顶部栏和/或底部栏(取决于视图控制器中显示的内容)设置为“不透明”。然后调整表视图的大小以适合导航栏和工具栏/选项卡栏。
最后,添加两个约束:
无论方向如何,对我来说效果都很好。
In your top level View Controller, in the "Simulated Metrics"-settings, set Top Bar and/or Bottom Bar (depending on what's displayed in your View Controller) to "opaque". Then resize the Table View to fit beween the Navigation Bar and the Tool Bar/Tab Bar.
Finally, add two constraints:
Worked very well for me, regardless of orientation.
如果您不使用 Storyboard,您可以尝试以下(快速)代码:
如果您有工具栏或(如果您使用 TabBarController),您也需要调整底部:
请注意,这是一个简单且“粗糙”代码。如果需要的话你可以把它变得更漂亮:)
If you are not using Storyboard, you could try the following (swift) code:
If you have a toolbar or (if you are using a TabBarController), you'll need to adjust the bottom too:
Please note that this is a simple and 'rough' code. You can make it prettier if needed :)