简体   繁体   English

如何使用自动布局动态添加视图

[英]How to Dynamically add a View using Auto Layout

I have this view(pink) in scrollview :我在滚动视图中有这个视图(粉红色):

enter image description here在此处输入图片说明

I want this :我要这个 :

when I tap on 'add' button 'new element' button shows and when I re-tap on 'add' button , 'new element ' button hides but I want also this :当我点击“添加”按钮时会显示“新元素”按钮,当我重新点击“添加”按钮时,“新元素”按钮会隐藏,但我也想要这个:

when 'new element' button is visible the pink view's height is like in the photo , but when 'new element ' button is not visible the pink view is to decrease the height , but I don't be able to set this situation by auto layout.当“新元素”按钮可见时,粉红色视图的高度就像照片中的一样,但是当“新元素”按钮不可见时,粉红色视图会降低高度,但我无法通过自动设置这种情况布局。

Can you help me?你能帮助我吗?

You can try something like this: new element button have boolean "isHidden" in case true or false just set your pink view height (pink.frame.size.height),if is hidden button decrease the height if is not hidden increase the height你可以尝试这样的事情:新元素按钮有布尔值“isHidden”,如果真或假只是设置你的粉红色视图高度(pink.frame.size.height),如果隐藏按钮降低高度如果不隐藏增加高度

if newElementButton.isHidden { pinkView.frame.size.height = 50 }
 else { pinkView.frame.size.height = 100 }

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

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