layoutIfNeeded奇怪的动画故障(layoutIfNeeded weird animation glitch)

编程入门 行业动态 更新时间:2024-10-24 22:18:36
layoutIfNeeded奇怪的动画故障(layoutIfNeeded weird animation glitch)

我正在为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.

更多推荐

本文发布于:2023-07-23 18:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235583.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:故障   奇怪   动画   layoutIfNeeded   animation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!