我正在为UITextField调整大小。 我正在使用Autolayout的约束。 我有H:|-[textField] -(8)-[label]-(8)-[image]-| 在我的故事板中的约束。
我为从屏幕飞出的标签设置动画,删除textField和标签之间的约束,然后在图像和textField之间创建一个新约束。 当我为view.layoutIfNeeded()设置动画时,textField内的文本会view.layoutIfNeeded()到textField的左上角,然后进入其正常位置。
为什么会这样,我怎么能阻止它呢?
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?
最满意答案
除了您正在讨论的约束之外,您可能还有待处理的布局操作。 在进行约束更改之前,尝试调用layoutIfNeeded一次,然后添加约束并再次在动画块内调用layoutIfNeeded 。
这将确保只有您想要设置动画的约束更改实际上是动画的。
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.
更多推荐
发布评论