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

mkoppanen picture mkoppanen  ·  3Comments

aeves313 picture aeves313  ·  4Comments

Shehryar picture Shehryar  ·  7Comments

cjwirth picture cjwirth  ·  4Comments

swiftli picture swiftli  ·  9Comments