Skip to content

Instantly share code, notes, and snippets.

@0xABCCBA
Created January 8, 2019 02:53
Show Gist options
  • Save 0xABCCBA/9b3030ccd815b746e19a17bb5d32fe44 to your computer and use it in GitHub Desktop.
Save 0xABCCBA/9b3030ccd815b746e19a17bb5d32fe44 to your computer and use it in GitHub Desktop.
use layoutIfNeeded
// use a button click to show how layoutIfNeeded() works
// article link: https://medium.com/@abhimuralidharan/ios-swift-setneedslayout-vs-layoutifneeded-vs-layoutsubviews-5a2b486da31c
@IBAction func heightPressed(_ sender: AnyObject) {
view.layoutIfNeeded()
if(self.blueHeight.constant == 25.0)
{
self.blueHeight.constant = self.view.bounds.height - 100.0
}
else
{
self.blueHeight.constant = 25.0
}
UIView.animate(withDuration: 2.0, animations: {
self.view.layoutIfNeeded()
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment