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

查看:44
本文介绍了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天全站免登陆