UIStackView隐藏视图动画 [英] UIStackView Hide View Animation

查看:1108
本文介绍了UIStackView隐藏视图动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 11中,隐藏动画在 UIStackView 中的行为已经改变,但我无法在任何地方找到此文档。

In iOS 11 the behaviour of the hide animation within a UIStackView has changed, but I have been unable to find this documented anywhere.

iOS 10

iOS 11

两者中的代码是:

UIView.animate(withDuration: DiscoverHeaderView.animationDuration,
                       delay: 0.0,
                       usingSpringWithDamping: 0.9,
                       initialSpringVelocity: 1,
                       options: [],
                       animations: {
                            clear.isHidden = hideClear
                            useMyLocation.isHidden = hideLocation
                        },
                       completion: nil)

怎么做我在iOS 11上恢复了以前的行为吗?

How do I restore the previous behaviour on iOS 11?

推荐答案

刚出现同样的问题。
修复是在动画块中添加 stackView.layoutIfNeeded()。其中 stackView 是您希望隐藏的项目的容器。

Just had the same issue. The fix is adding stackView.layoutIfNeeded() inside the animation block. Where stackView is the container of the items you're wishing to hide.

UIView.animate(withDuration: DiscoverHeaderView.animationDuration,
                   delay: 0.0,
                   usingSpringWithDamping: 0.9,
                   initialSpringVelocity: 1,
                   options: [],
                   animations: {
                        clear.isHidden = hideClear
                        useMyLocation.isHidden = hideLocation
                        stackView.layoutIfNeeded()
                    },
                   completion: nil)

不确定为什么这在iOS 11中突然出现问题,但公平地说它始终是推荐的方法。

Not sure why this is suddenly an issue in iOS 11 but to be fair it has always been the recommended approach.

这篇关于UIStackView隐藏视图动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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