Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

layoutIfNeeded weird animation glitch

I am animating a resize of a UITextField. I am using Autolayout with constraints. I have H:|-[textField] -(8)-[label]-(8)-[image]-| in constraints in my storyboard.

I animate the label flying off screen, remove the constraint between the textField and the label, and then create a new constraint between the image and the textField. When I animate view.layoutIfNeeded(), the text inside the textField glitches into the top-left corner of the textField and then animates into its normal place.

Why is this happening and how can I stop it?

like image 264
vrwim Avatar asked Mar 20 '15 12:03

vrwim


1 Answers

It's likely that you have pending layout operations other than the constraint you're talking about. Try calling layoutIfNeeded once before you make the constraint changes, then add the constraints and call layoutIfNeeded again inside the animation block.

This will ensure that only the constraint changes you intend to animate are actually animated.

like image 59
rounak Avatar answered Sep 27 '22 22:09

rounak