简体   繁体   English

自定义表格单元格中的堆栈视图

[英]stackview in custom table cell

In a custom table cell, I'm trying to hide/show view on a button click.在自定义表格单元格中,我试图在单击按钮时隐藏/显示视图。 I'm able to achieve this but couldn't able to remove the blank space.我能够实现这一点,但无法删除空格。 How to remove those blank spaces.如何删除那些空格。 I used auto constraints for stack view but it seems to be no use.我对堆栈视图使用了自动约束,但似乎没有用。 can you anyone suggest a simple way to remove the blank spaces when the view is in a hidden state.当视图处于隐藏状态时,任何人都可以提出一种简单的方法来删除空格。

Note: custom cell should adjust its height automatically depending on the content when it's attached to table view注意:自定义单元格在附加到表格视图时应根据内容自动调整其高度

Edit one编辑一

如您所见,开始日期和结束日期位于底部,没有任何动态高度变化

As you can see the start date and end date are placed at the bottom without any dynamic height change如您所见,开始日期和结束日期位于底部,没有任何动态高度变化

自定义单元格的预览。在此单元格堆栈视图中,底部最初设置为隐藏。

Preview of the custom cell.自定义单元格的预览。 In this Cell stack view at the bottom is set to hidden initially.在此单元格堆栈视图中,底部最初设置为隐藏。

You have a couple options...你有几个选择...


1) Use another stack view: 1)使用另一个堆栈视图:

  • Embed the top "always visible" elements in a UIViewUIView嵌入顶部的“始终可见”元素
  • Embed that view and the "sometimes hidden" stack view in a vertical "outer" stack view在垂直的“外部”堆栈视图中嵌入该视图和“有时隐藏”的堆栈视图
  • Constrain this new "outer" stack view to all 4 sides of the cell's content view将这个新的“外部”堆栈视图约束到单元格内容视图的所有 4 个侧面

Now, when you hide the "sometimes hidden" stack view, it will not take up any space.现在,当您隐藏“有时隐藏”堆栈视图时,它不会占用任何空间。


2) Use multiple bottom constraints: 2)使用多个底部约束:

  • Keep the bottom constraint from the bottom of the "sometimes hidden" stack view to the bottom of the cell's content view.保持从“有时隐藏”堆栈视图底部到单元格内容视图底部的底部约束。 Make it an IBOutlet - we'll call it whenHiddenConstraint将其设为IBOutlet - 我们将其whenHiddenConstraint
  • Add a constraint from the bottom of the bottom-most "always visible" element to the bottom of the cell's content view.从最底部的“始终可见”元素的底部到单元格内容视图的底部添加一个约束。 Make it an IBOutlet - we'll call it whenVisibleConstraint将其设为IBOutlet - 我们将其whenVisibleConstraint
  • Set the Priority on the whenVisibleConstraint to 750whenVisibleConstraint的优先级设置为750
  • Set the Priority on the whenHiddenConstraint to 250whenHiddenConstraint的优先级设置为250

Now, in your code, when hiding the "sometimes hidden" stack view:现在,在您的代码中,隐藏“有时隐藏”堆栈视图时:

theStackView.isHidden = true
whenVisibleConstraint.priority = .defaultLow
whenHiddenConstraint.priority = .defaultHigh

when you want to show the "sometimes hidden" stack view:当您想显示“有时隐藏”的堆栈视图时:

theStackView.isHidden = false
whenHiddenConstraint.priority = .defaultLow
whenVisibleConstraint.priority = .defaultHigh

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

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