我在名为Stages
的文件中创建了一个新的UIstackView实例 class Stages: UIStackView {
override init(frame: CGRect) {
super.init(frame: frame)
}
required init(coder: NSCoder) {
super.init(coder: coder)
}
func SetUpStageOne() {
add some views inside a stackview
func SetUpStageTwo() {
add some new views inside a stackview
}
我试图弄清楚如何让StackView像运行时一样出现在运行时
class Stages: UIStackView {
override init(frame: CGRect) {
super.init(frame: frame)
if score == 0 {
SetUpStageOne()
}
if score == 1 {
SetUpStageTwo()
}
required init(coder: NSCoder) {
super.init(coder: coder)
if score == 0 {
SetUpStageOne()
}
if score == 1 {
SetUpStageTwo()
}
}
func SetUpStageOne() {
add some views inside a stackview
func SetUpStageTwo() {
add some new views inside a stackview
}
当分数== 0时,我可以显示第一个StackView 但是在整个游戏中,我想更新stackview,以便当得分== 1时出现第二个堆栈视图,但该dosnt会发生。
答案 0 :(得分:0)
尝试在每个setupstage方法的末尾使用self.setNeedsLayout()。这将调整视图子视图的布局。 self.setNeedsDisplay()将无效,因为如果您重写了draw(_ rect)函数,它将重置视图。