简体   繁体   English

iOS Autolayout具有多个具有动态高度的视图

[英]iOS Autolayout with multiple views with dynamic heights

I'm trying to achieve the following: 我正在努力实现以下目标:

MyViewcontroller MyViewcontroller

  • MyCustomTextField (height 50) MyCustomTextField(高度50)
  • MyCustomTextField (height 50) MyCustomTextField(高度50)
  • MyCustomTextField (height 50) MyCustomTextField(高度50)

Now that is easier enough in an XIB file. 现在,在XIB文件中这已经足够容易了。

However, I want to be able call something like MyCustomTextField showError:@"an error" and this to change the height (to say 80) of the related field (animated). 但是,我希望能够调用MyCustomTextField showError:@“错误”之类的东西,以更改相关字段(动画)的高度(例如80)。

Can someone describe how to do this with Autolayout? 有人可以描述如何使用自动排版吗? My main issue is ensuring the other 'MyCustomTextField's move down at the same time, as the height of the previous field will have increased. 我的主要问题是确保另一个“ MyCustomTextField”同时向下移动,因为前一个字段的高度将增加。

Any help or pointers would be appreciated. 任何帮助或指针,将不胜感激。

You can try the below approach; 您可以尝试以下方法;

  1. Create IBOutlet's for the height constraint of each textfield(your custom textfield). 为每个文本字段(您的自定义文本字段)的高度约束创建IBOutlet。 You can then programmatically update the constraints constant according to the text size. 然后,您可以根据文本大小以编程方式更新约束常量。
  2. Apply vertical spacing constraints between the textfields. 在文本字段之间应用垂直间距约束。 So that the textfields will move with respect to their above textfields. 这样文本字段将相对于其上面的文本字段移动。

Hope this helps you. 希望这对您有所帮助。

开始工作-我在myviewcontroller中为高度设置了约束,这是错误的,这阻止了它增加高度。

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

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