alexander alexander - 1 year ago 110
Swift Question

dynamic adding view 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?

Answer Source

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

if newElementButton.isHidden { pinkView.frame.size.height = 50 }
 else { pinkView.frame.size.height = 100 }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download