简体   繁体   English

具有自动布局的多个动态视图

[英]Multiple Numbers of dynamic Views with Autolayout

在此处输入图片说明

As you can see i try to build some clickable Views (with IB and Autolayout) which are completely dynamic. 如您所见,我尝试构建一些完全动态的可单击视图(使用IB和自动布局)。 I get my data from my Server so until the response arrives i don´t know which View i have to show and which of theese views should be hidden. 我从服务器获取数据,因此直到响应到来之前,我都不知道必须显示哪个视图以及应该隐藏哪些视图。

The Problem is, that the Views i don´t need during runtime should not only be hidden but also completley removed from the tableHeaderView , so that the View under the removed one, comes up. 问题是,在运行时我不需要的View不仅应该被隐藏,而且应该从tableHeaderView删除completley,以便出现被删除的View。 I know that removing Constraints during runtime ist not the best choice, so i tried to set a fixed height for the four views (as NSLayoutConstraint) and if i don´t need one of theese Views i set the Height Constraint to zero like: 我知道在运行时删除Constraints并不是最好的选择,所以我尝试为四个视图设置一个固定的高度(如NSLayoutConstraint),如果我不需要这些视图之一,则将“ Height Constraint设置为零,例如:

self.hotlineViewHeightConstraint.constant = 0.0f;

This works fine, but now all of the Subviews making trouble (UIImageView and the Labels). 这可以正常工作,但是现在所有子视图都出现了问题(UIImageView和Labels)。 Because the UIImageView also have a fixed Height and some of the Labels too. 因为UIImageView也具有固定的Height和一些Labels。 And last but not least the vertical Constraints between the Labels and its superview are also a Problem because they don´t shrink to zero automatically. 最后但并非最不重要的一点是,标签及其超级视图之间的垂直约束也是一个问题,因为它们不会自动缩小为零。 I also tried to play with the priority of the Subview Constraints and it still "works" but the Warnings still remain. 我还尝试使用“子视图约束”的优先级,它仍然“有效”,但警告仍然存在。 Any Ideas how to get this work without making a ton of NSLayoutConstraint and setting everthing to zero?? 任何想法如何在不进行大量NSLayoutConstraint并将所有设置为零的情况下进行这项工作?

Four Views like in the Screenshot above are the maximum Number of Views, so its equal or less Views than this. 上面的屏幕快照中的四个视图是最大视图数,因此它等于或小于此视图。

您是否考虑过将所有这些内容放入另一个UITableview中。

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

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