thejuki thejuki - 7 months ago 87
Swift Question

Swift: Dynamic UIView that pushes UIViews below it after a resize

What I am trying to is emulate the effect of the Jquery .slideDown() effect in Swift for an iOS app.

-I need a UIView to auto-resize based on the length of the text in it.

-The UIView needs to push other UIViews below it down.

-There needs to be a button above the UIView or on it then when tapped will cause a "Slide down" (Showing the extra text and expanding the fit the text). After re-tapping the button the UIView will resize and the text will be hidden.

Below is a GIF of the Jquery .slideDown() effect I would like to mimic in Swift.

Is this possible? Do I need to import a library?

GIF of the Jquery version


Is this possible?

Yes this is possible using autolayout. Here is a great tutorial on how to get started with autolayout. Here is a brief tutorial on animating autolayout constraint changes. If you setup your constraints properly you should be able to do something as simple as:


and the requested changes will happen.

Do I need to import a library?

No external libraries are needed. You can however look here to see if something similar exist.