gpt4 book ai didi

ios - 动画在 Swift 中显示和隐藏 View

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:36:10 25 4
gpt4 key购买 nike

我有这个功能:

func showwAndHideFilterMenu(category : Int) {

if showFilterMenu == false{
UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseInOut, animations: {
self.filterView.isHidden = false
self.showFilterMenu = true
}) { (isCompleted) in
}

} else {
UIView.animate(withDuration: 0.6, delay: 0, options: .curveEaseInOut, animations: {
self.filterView.isHidden = true
self.self.showFilterMenu = false
}) { (isCompleted) in
}
}
}

我有一个显示和隐藏 View 的函数。我想添加一个动画来显示/隐藏这个 View 。怎么做?动画的方向将从上到下。

有人知道怎么做吗?

最佳答案

您需要操作 alpha 属性而不是 isHidden 属性来为 UIView 淡入淡出动画。

尝试以下操作:

func showAndHideFilterMenu(category : Int) {
if showFilterMenu == false {
self.filterView.alpha = 0.0
self.filterView.isHidden = false
self.showFilterMenu = true

UIView.animate(withDuration: 0.6,
animations: { [weak self] in
self?.filterView.alpha = 1.0
})
} else {
UIView.animate(withDuration: 0.6,
animations: { [weak self] in
self?.filterView.alpha = 0.0
}) { [weak self] _ in
self?.filterView.isHidden = true
self?.showFilterMenu = false
}
}
}

关于ios - 动画在 Swift 中显示和隐藏 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50851374/

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