处理iOS 10中的AutoLayout约束动画差异? [英] Handling AutoLayout constraint animation differences in iOS 10?

查看:95
本文介绍了处理iOS 10中的AutoLayout约束动画差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到在iOS 10 Beta 5(即将尝试Beta 6)中,AutoLayout约束动画的行为有所不同。



例如,这种方法确实

  [view addConstraints:@ [constraints ...]]; 

[view setNeedsUpdateConstraints];
[view layoutIfNeeded];

[UIView animateWithDuration:...
{
/ *在这里调整约束... * /
[view layoutIfNeeded]; //仅自上次layoutIfNeeded()调用以来的调整约束应使动画随时间变化。

}完成:{...}];

...在我的测试中,最初使用 addConstraints()添加的约束还将在iOS 10中使用UIView animateWithDuration()块进行动画设置...这会引起一些时髦/不希望的内容



例如,在数组中设置左/右约束(但在块中设置垂直约束)会导致整个视图进行动画处理

有人知道如何针对iOS 9(及更低版本)正确执行此操作吗?以及10?

解决方案

尝试在视图的超级视图上调用 layoutIfNeeded ,而不是视图本身。



-



我有一个类似的问题,我的视图应该从顶部以0高度动画,然后向下到> 0高度(即(0,0,320,0)到(0,0,320,44))。



将Xcode 8与iOS 10的动画行为有很大不同。视图不是从顶部向下动画,而是向上和向下动画。



我解决了这个问题,而不是在视图上调用 layoutIfNeeded 本身,将其称为视图的超级视图。



希望它会有所帮助!





有用的评论由@Ramiro:


根据文档, layoutIfNeeded 列出了子视图(但不考虑当前视图本身)。因此,为了更新当前视图布局,您需要从超级视图调用 layoutIfNeeded



I've noticed that in iOS 10 Beta 5 (about to try Beta 6), AutoLayout constraint animation behaves a bit differently.

For example, this approach does not work the same as it did in previous iOS releases:

[view addConstraints:@[constraints...]];

[view setNeedsUpdateConstraints];
[view layoutIfNeeded];

[UIView animateWithDuration:...
{
    /* adjust constraint here... */
    [view layoutIfNeeded]; // Only the adjusted constraints since previous layoutIfNeeded() call should animate change with duration.

} completion:{ ... }];

... In my testing, the constraints initially added with addConstraints() will also animate in iOS 10 with the UIView animateWithDuration() block... which is causing some funky/undesirable behavior so far.

For example, setting the left/right constraints in the array (but the vertical constraints in the block) causes the entire view to animate onto the screen diagonally with this approach... which is totally incorrect.

Does anyone know how to do this correctly for both iOS 9 (and below), as well as 10?

解决方案

Try calling layoutIfNeeded on the view's superview, instead of the view itself.

--

I had a similar problem, my view was supposed to animate from the top at a 0 height, downward to a > 0 height (i.e. (0, 0, 320, 0) to (0, 0, 320, 44)).

Using Xcode 8 with iOS 10, the animation behavior was much different. Instead of animating downward from the top, the view animates up & down from the vertical center of the destination frame.

I fixed this by, instead of calling layoutIfNeeded on the view itself, calling it on the view's superview. Somehow, the behavior was restored.

Hope it helps!


Helpful comment by @Ramiro:

According to the documentation, layoutIfNeeded lays out the subviews (but doesn't contemplate the current view itself). So, in order to update the current view lay out, you need to call layoutIfNeeded from the super view.

这篇关于处理iOS 10中的AutoLayout约束动画差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆