简体   繁体   English

不占据整个屏幕的表格视图,在一个堆栈视图中

[英]Table Views that don't take up the whole screen, within a stack view

I'm having problems trying to implement a layout for my app.我在尝试为我的应用程序实现布局时遇到问题。 Whenever I use tableviews, it wants to take up as much space as possible.每当我使用 tableviews 时,它都希望占用尽可能多的空间。 I'm trying to have (from top to bottom) a tableview with two rows, a text field, and a horizontal stack view rooted to the bottom with two buttons.我试图(从上到下)有一个包含两行、一个文本字段和一个带有两个按钮的底部的水平堆栈视图的 tableview。 Something like this:像这样的东西:

Mockup小样

My issue is that constraining this has been a bit of a nightmare.我的问题是,限制这有点像一场噩梦。 At the moment I actually have the view looking just like this, but its hard coded with the top constraint of the tableview being inset by 400. I need a way for this to be flexible, as when I click on the textfield, i'm going to have that adjust to the top of the keyboard, along with the tableview above it.目前我的视图实际上看起来像这样,但是它的硬编码表视图的顶部约束被 400 插入。我需要一种灵活的方法,因为当我点击文本字段时,我是将把它调整到键盘的顶部,以及它上面的 tableview。

At the moment I currently have the TableView within a View, which is in a StackView with the textfield and bottom stack view with the buttons.目前,我目前在一个视图中有 TableView,它在一个带有文本字段的 StackView 和带有按钮的底部堆栈视图中。 How can I set up the constraints in such a way that the entire stack seems to appear rooted to the bottom of the screen?如何设置约束,使整个堆栈似乎都扎根于屏幕底部?

I'm sorry if this is a broad question, it's more of a 'How should I go about this' rather than 'How can I do this' kind of question.很抱歉,如果这是一个广泛的问题,它更像是一个“我应该怎么做”而不是“我该怎么做”这样的问题。 I should mention I'm doing this programatically too, using SnapKit for the constraints.我应该提到我也在以编程方式执行此操作,使用 SnapKit 作为约束。

Thanks all!谢谢大家!

Fixed by rethinking the whole thing an simplifying.通过重新思考整个事情并简化来解决。 Took the table view out of the stack, put that and the stack view in. Then the problem was my original one, the cells being stuck to the top of the screen and constraining not changing it at all.把表格视图从堆栈中取出,把它和堆栈视图放进去。然后问题是我原来的那个,单元格被粘在屏幕的顶部并且限制不改变它。

So I flipped the table view using所以我使用翻转了表格视图

tableView.transform = CGAffineTransform(scaleX: 1, y: -1)

And doing the same to the two cells to flip them back to normal orientation.并对两个单元格执行相同操作,将它们翻转回正常方向。 Now the view is perfect!现在景色很完美! Hope this helps anyone in the future希望这对未来的任何人都有帮助

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

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