【问题标题】:Shrink heightConstraint animation issue收缩高度约束动画问题
【发布时间】:2019-04-18 14:19:21
【问题描述】:

我正在尝试制作上拉菜单视图

我使用 xib 制作了这个拉起视图并附加到 ViewController

并在上拉视图中添加平移手势

最后,我使用平移手势更新了动画的高度约束。

func pullUpControlView(_ pullUpControlView: PullUpControlView, didPanned height: CGFloat, animated: Bool) {
    self.pullUpControlViewHeightConstraint?.constant = height
    if animated {
        UIView.animate(withDuration: 10, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: .curveEaseOut, animations: {
            self.view.layoutIfNeeded()
        }, completion: nil)
    }
}

这是我的代码,当视图达到最大高度时,它的动画效果很好,

但是当最小化视图时,视图会立即最小化并开始缓慢向下移动(奇怪的动画)

我怎样才能正确地制作这个动画(从上到下缩小高度)

【问题讨论】:

  • 您是说视图立即最小化并向下移动...!您对视图有何期待?它(视图)应该做什么?
  • 您能否添加一些您尝试存档的屏幕截图并添加上拉视图约束?
  • 我添加了我的情况,我只是希望我的视图高度平滑缩小,但它不起作用
  • 请上传一个重现问题的示例项目。在我看来,您发布的代码似乎没有问题。我猜你的问题来自你项目的其他地方。您在其他地方打电话给layoutIfNeeded() 吗?

标签: ios nslayoutconstraint ios-autolayout


【解决方案1】:
func pullUpControlView(_ pullUpControlView: PullUpControlView, didPanned height: CGFloat, animated: Bool) {
    UIView.animate(withDuration: 5, animations: {() -> Void in
        self.view.layoutIfNeeded()
    }, completion: {(_ finished: Bool) -> Void in
        self.pullUpControlViewHeightConstraint?.constant = height
        self.view.layoutIfNeeded()
        //if animation is finished ("finished" == *YES*), then hidden = "finished" ... (aka hidden = *YES*)
    })
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多