繁体   English   中英

UIStackView,使用调整大小的动画隐藏子视图

[英]UIStackView, hiding subview with resizing animation

我在这里看到了UIStackView中隐藏/显示子视图的非常流畅的动画。

我尝试在自己的应用程序中重现它,但是遇到了问题。

在动画过程中隐藏的视图不会调整大小。 它只是等到动画完成然后消失。 与上面链接的示例中的clear button相反。

我的代码:

UIView.animate(withDuration: 0.5,
               delay: 0.0,
               usingSpringWithDamping: 0.9,
               initialSpringVelocity: 1,
               options: [],
               animations: {
                    self.acceptDeclineBar.isHidden = !newState
                    self.view.layoutIfNeeded()
                },
               completion: nil)

UIStackViewUIStackView提供隐藏/显示动画的大小调整动画还是我需要使用高度限制为自己实现动画?

动画完成后,您的视图(self.acceptDeclineBar)将隐藏。 尝试在动画之前隐藏。

self.acceptDeclineBar.isHidden = !newState

 UIView.animate(withDuration: 0.3){ [weak self]
                    self?.view.layoutIfNeeded()
}

或者您可以使用Height Constraint代替隐藏

acceptDeclineBarHeightConstraint.constant = newState ? 60 (whatever Visbale size) : 0 (Hide)
 UIView.animate(withDuration: 0.3){ [weak self]
                    self?.view.layoutIfNeeded()
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM