Animation Not working on remake
Info | Value |
----------------------|-------------------------|
Platform | ios
Platform Version | 11.0
SnapKit Version | 4.0.0
Integration Method | cocoapods
I am going to change layout of label and apply remake constraints.
But animation does not working,
This code fire when user wants to start typing in textfield,
UIView.animate(withDuration: AnimationInterval, animations: {
self.lblName.font = UIFont(name: "Verdana", size: 12.0)
self.lblName.snp.remakeConstraints({ (make) in
make.centerX.equalTo(self)
make.top.equalTo(self.margin)
make.left.equalTo(self.margin)
make.right.equalTo(-self.margin * 2)
make.height.equalTo(self.lblHeight)
})
}) { (flag) in
self.txtField.becomeFirstResponder()
}
animation does not work.
take the remake constraints out of the animation block. make a func for animating, change the constraints, and then in the animation block, call the view's superview LayoutIfNeeded.
self.lblName.snp.remakeConstraints({ (make) -> Void in
make.centerX.equalTo(self)
make.top.equalTo(self.margin)
make.left.equalTo(self.margin)
make.right.equalTo(-self.margin * 2)
make.height.equalTo(self.lblHeight)
})
UIView.animate(withDuration: AnimationInterval, animations: {
self.layoutIfNeeded()
}) { (flag) in
}
this is done.
@8bitramen's answer is correct, need to call layoutIfNeeded in the animation block and setNeedsLayout outside it after updating constraints
Most helpful comment
this is done.