Snapkit: How to animate width/height and constrains

Created on 25 Feb 2016  Â·  3Comments  Â·  Source: SnapKit/SnapKit

Hello and sorry for posting here, but I can't find any other information about this.

I want to animate the height of a UIView to 0.0 and update the constrains at the same time. How would I do that?

Thanks in advance.

Most helpful comment

@netgfx

Something like:

box.snp_makeConstraints { make in
    make.left.equalTo(50)
}
…
UIView.animateWithDuration(5.0) {
  box.snp_updateConstraints { make in
      make.left.equalTo(50)
  }
  box.superview.layoutIfNeeded()
}

You may need to remakeConstraints rather than updateConstraints if you're not altering _just_ the constant value.

All 3 comments

@netgfx

Something like:

box.snp_makeConstraints { make in
    make.left.equalTo(50)
}
…
UIView.animateWithDuration(5.0) {
  box.snp_updateConstraints { make in
      make.left.equalTo(50)
  }
  box.superview.layoutIfNeeded()
}

You may need to remakeConstraints rather than updateConstraints if you're not altering _just_ the constant value.

Thanks that worked.

superview.layoutIfNeeded() did the trick

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexpersian picture alexpersian  Â·  4Comments

aeves313 picture aeves313  Â·  4Comments

danieleggert picture danieleggert  Â·  3Comments

Cookiezby picture Cookiezby  Â·  8Comments

jagdish24 picture jagdish24  Â·  3Comments