我有这个功能:
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 属性,而不是 UIView 淡入淡出动画的 isHidden 属性。
尝试以下方法:
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/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |