gpt4 book ai didi

ios - UIView的高度约束动画

转载 作者:搜寻专家 更新时间:2023-11-01 07:05:16 26 4
gpt4 key购买 nike

我有一个名为 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怎样才能达到理想的效果?

最佳答案

动画主视图

 @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")
}
}

关于ios - UIView的高度约束动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48450959/

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