ios - Swift 中的动画显示和隐藏 View
<p><p>我有这个功能:</p>
<pre><code>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
}
}
}
</code></pre>
<p>我有一个显示和隐藏 View 的功能。我想添加一个动画来显示/隐藏这个 View 。怎么做?动画的方向是从上到下。</p>
<p>有人知道怎么做吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您需要操作 alpha 属性,而不是 UIView 淡入淡出动画的 isHidden 属性。 </p>
<p>尝试以下方法:</p>
<pre><code>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: { in
self?.filterView.alpha = 1.0
})
} else {
UIView.animate(withDuration: 0.6,
animations: { in
self?.filterView.alpha = 0.0
}) { _ in
self?.filterView.isHidden = true
self?.showFilterMenu = false
}
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - Swift 中的动画显示和隐藏 View ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/50851374/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/50851374/
</a>
</p>
页:
[1]