我有4个单独的视图,并且我想在按下其中一个按钮时隐藏其他3个视图,但它们在堆栈视图中,但是.isHidden = true
出于某种原因没有隐藏视图,它当他们不在堆栈中时,它可以很好地工作,查看有关如何实现此建议的任何建议?
@IBAction func qbpressed(_ sender: Any) {
QBContainer.isHidden = false
WRContainer.isHidden = true
RBContainer.isHidden = true
QBIndicator.isHidden = false
WRIndicator.isHidden = true
RBIndicator.isHidden = true
TEIndicator.isHidden = true
QBButton.setTitleColor(#colorLiteral(red: 0, green: 0.5008062124, blue: 1, alpha: 1), for: .normal)
WRButton.setTitleColor(#colorLiteral(red: 0.7540688515, green: 0.7540867925, blue: 0.7540771365, alpha: 1), for: .normal)
RBButton.setTitleColor(#colorLiteral(red: 0.7540688515, green: 0.7540867925, blue: 0.7540771365, alpha: 1), for: .normal)
TEButton.setTitleColor(#colorLiteral(red: 0.7540688515, green: 0.7540867925, blue: 0.7540771365, alpha: 1), for: .normal)
if intersitial.isReady{
intersitial.present(fromRootViewController: self)
}
}
答案 0 :(得分:2)
将视图设置为隐藏应该使其不再可见,无论它是否位于UIStackView
内。
UIStackView
的好处在于,它通过isHidden属性提供了免费的动画,如下所示:
// Assuming stackViewSubView.isHidden == false here
UIView.animate(withDuration: 0.25, animations: {
self.stackViewSubView.isHidden = true
self.view.layoutIfNeeded()
})
答案 1 :(得分:2)
isHidden属性不起作用,但是您可以使用alpha并获得相同的结果,
QBIndicator.alpha = 1.0
适用于QBIndicator.isHidden = false
和
QBIndicator.alpha = 0.0
适用于QBIndicator.isHidden = true