【问题标题】:Height constraint animation of UIViewUIView的高度约束动画
【发布时间】:2018-01-25 19:59:59
【问题描述】:

我有名为 DetailView 的 UIView 具有以下约束:

DetailView.top = top
DetailView.trailing = Safe Area.trailing
DetailView.leading = Safe Area.leading
height = 295

全部在 StoryBoard 中制作。 DetailView is this gray rectangle on an image

我想在点击按钮后改变这个 UIView 的高度,所以我有 IBAction 来实现这个

@IBAction func detailViewTapped(_ sender: Any) {
        if detailViewHeightConstraint.constant < 500 {
            detailViewHeightConstraint.constant = 523
            UIView.animate(withDuration: 0.5) {
                self.detailView.layoutIfNeeded()
            }
            arrowImageView.image = UIImage(named: "up-arrow")
        } else {
            detailViewHeightConstraint.constant = 295
            UIView.animate(withDuration: 0.5) {
                self.detailView.layoutIfNeeded()
            }
            arrowImageView.image = UIImage(named: "down-arrow")
        }
    }

改变尺寸效果很好,但动画效果不行。我想实现扩展到底部的效果,但是动画在屏幕之间开始一些东西,并且正在扩展到底部和顶部。 Start of animation can be seen on this picture怎样才能达到理想的效果?

【问题讨论】:

    标签: ios swift animation uiview


    【解决方案1】:

    动画主视图

     @IBAction func detailViewTapped(_ sender: Any) {
        if detailViewHeightConstraint.constant < 500 {
            detailViewHeightConstraint.constant = 523
            UIView.animate(withDuration: 0.5) {
                self.view.layoutIfNeeded()
            }
            arrowImageView.image = UIImage(named: "up-arrow")
        } else {
            detailViewHeightConstraint.constant = 295
            UIView.animate(withDuration: 0.5) {
                self.view.layoutIfNeeded()
            }
            arrowImageView.image = UIImage(named: "down-arrow")
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-20
      相关资源
      最近更新 更多