animation - 处理 iOS 10 中的 AutoLayout 约束动画差异?

标签 animation autolayout uikit nslayoutconstraint ios10

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

例如,这种方法与以前的 iOS 版本不同:

[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:{ ... }];

...在我的测试中,最初添加的约束是 addConstraints()还有在 iOS 10 中使用 UIView 制作动画 animateWithDuration()阻止......到目前为止,这导致了一些时髦/不受欢迎的行为。

例如,设置数组中的左/右约束(但 block 中的垂直约束)使整个 View 沿对角线在屏幕上动画用这种方法......这是完全不正确的。

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

最佳答案

尝试调用layoutIfNeeded在 View 的 super View 上,而不是 View 本身。

--

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

在 iOS 10 中使用 Xcode 8,动画行为有很大不同。 View 不是从顶部向下动画,而是从目标帧的垂直中心向上和向下动画。

我解决了这个问题,而不是调用 layoutIfNeeded在 View 本身上,在 View 的父 View 上调用它。不知何故,行为恢复了。

希望能帮助到你!

@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.

关于animation - 处理 iOS 10 中的 AutoLayout 约束动画差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38965727/

相关文章:

Swift3 设置父 View 相对于父 View 的约束

ios - 在将 View 添加到 View 树之前如何计算 UIViewController 高度?

iphone - 打印应用程序当前堆栈跟踪的简单方法?

css - 如何添加一些CSS/html5效果让它有火热的错觉?

java - 制作动画叠加 View

javascript - 如何将 (CSS/HTML) 包链接在一起。 CSS/HTML -> CSS/HTML -> CSS/HTML

ios - iOS 中简单动态布局入门 (Xcode 6/Swift)

jquery - 使用 Velocity.js 或 Transit.js 来实现 CSS/JS/jQuery 动画?

ios - 使用自动布局进行战斗

iOS swift : Custom scroll animation for UIScrollView