【问题标题】:Animations: moving a UIView up and off the screen by its height - SWIFT动画:将 UIView 在屏幕上上下移动高度 - SWIFT
【发布时间】:2018-03-18 23:22:35
【问题描述】:

我正在尝试将 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
                })

【问题讨论】:

    标签: ios swift animation nslayoutconstraint


    【解决方案1】:

    您需要在动画块内调用 layoutIfNeeded(用于视图或其超级视图之一)。

    【讨论】:

    • 我按照您的建议在动画块内尝试了 self.viewContainingProgressBar.layoutIfNeeded() ,但它仍然不起作用。不确定这是否是您的意思……也许您可以帮我编写代码?
    • 尝试修改现有约束(您需要链接到插座)上的常量,而不是创建新约束。
    【解决方案2】:

    添加

    self.view.layoutIfNeeded()
    

    动画块内

    【讨论】:

      猜你喜欢
      • 2012-01-01
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多