gpt4 book ai didi

ios - 动画: moving a UIView up and off the screen by its height - SWIFT

转载 作者:行者123 更新时间:2023-11-30 11:40:16 25 4
gpt4 key购买 nike

我正在尝试将 UIView 在 ios 中按其高度在屏幕上上下移动。下面是我执行此操作的代码。我发现 UIView 确实向上移动并离开屏幕,但它并没有按预期缓慢移动,而是继续瞬时移动而没有动画。请问有人可以建议吗?

 UIView.animate(withDuration: 300, animations: {
let heightOfViewContainingProgrBar = self.viewContainingProgressBar.frame.height
self.viewContainingProgressBar.topAnchor.constraint(equalTo: self.view.topAnchor, constant: -heightOfViewContainingProgrBar).isActive = true
})

最佳答案

您需要在动画 block 内调用layoutIfNeeded(针对 View 或其 super View 之一)。

关于ios - 动画: moving a UIView up and off the screen by its height - SWIFT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49353851/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com