自上浆细胞,.自动布局和隐藏UIViews [英] Self sizing Cells,. Autolayout and hidden UIViews

查看:149
本文介绍了自上浆细胞,.自动布局和隐藏UIViews的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用自动布局自动设置一个单元的高度。但我想在我的细胞使用一些隐藏的UIViews。因此,在某些行,他们应该被隐藏。这里的问题是,如果标签仍有隐忧它就会自动版式所认可,它使用的空间。

i am using Autolayout to set automatically the height of a cell. But i want to use some hidden UIViews in my Cells. So in some rows they should be hidden. The problem here is, if the label is still hidden it gets recognized by autolayout and it uses the space.

所以我想我需要更新标签的高度,还是我约束的高度。

So i guess i need to update the height of my label, or the height of my Constraints.

什么是,如果我使用自动布局来隐藏单元格UI元素的正确方法是什么?

What is the correct way if i am using Autolayout to hide UIElements in a Cell?

我如何更新现有的(从故事板)约束?

How can i update an existing (from Storyboard) Constraint?

编辑:发现了我能够更新故事板的限制,这是正确的方式来处理这个问题? - 但是是正确的设置高度? (这只是一个示范项目)

Found out that i am able to update Constraints with Storyboard, is that the correct way to handle that? - but which is the correct one to setup the height? (This is just a Demo Project)

推荐答案

这是标准的任务与自动布局。目前,有解决此任务的方法有两种:

This is standard task with autolayout. Currently, there are two ways of solving this task:


  1. 删除隐藏视图

  2. 更改约束优先

的隐藏视图删除

看起来pretty容易,你不会有任何问题,如果你不使用的UITableView(你必须把它放回 prepareForReuse ) ,UICollectionView或您的数据,而你在屏幕上会出现,在那里你刚刚删除的意见。

Looks pretty easy and you won't have any problems if you don't use UITableView (you have to put it back in prepareForReuse), UICollectionView or your data can appear while you're on screen, where you've just removed views.

意见删除是重的操作,所以你需要三思而后行,如果你选择这种方式。

Removing of views is "heavy" operation, so you need to think twice, if you pick this way.

CustomCell.m

- (void) prepareForReuse {
 [super prepareForReuse];
 // add removed views again
 // establish constraints
}

- (void) configureCell {
 // check if you need to hide a view
 [view removeFromSuperview];
}

更改约束优先

假设,你有下面的单元格:

Assume, you have following cell:

查看A

视图B

如果乙方有时可以隐藏,然后指定视图A以下限制:
空间与750 B
底部空间与500的SuperView

If B sometimes can be hidden, then specify for View A following constraints: Space to B with 750 Bottom Space to superview with 500

如果您集合B为隐藏,变化的空间B = 500,底部空间的SuperView = 750。

If you set B as hidden, change space to B = 500, bottom space to superview = 750.

撤消 prepareForReuse

这篇关于自上浆细胞,.自动布局和隐藏UIViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆