我想要隐藏这些图片并使用相同的按钮取消隐藏它们。现在我有一个按钮连接2个动作。触摸向下和触摸向下重复。触摸向下重复按下按钮两次以取消隐藏图像。我只想按下它一次取消隐藏,就像我按下隐藏时一样。任何人都知道如何处理这个问题?
@IBAction func settingsCheck(sender: UIButton) {
c.hidden = true
d.hidden = true
e.hidden = true
f.hidden = true
g.hidden = true
a.hidden = true
b.hidden = true
cFour.hidden = true
settingsCheck.hidden = false
}
@IBAction func settingCheckButtonsUnhide(sender: UIButton) {
c.hidden = false
d.hidden = false
e.hidden = false
f.hidden = false
g.hidden = false
a.hidden = false
b.hidden = false
cFour.hidden = false
settingsCheck.hidden = true
}
答案 0 :(得分:5)
你应该使用!在实际的隐藏状态前面如下反转它:
@IBAction func settingsCheck(sender: UIButton) {
c.hidden = !c.hidden
d.hidden = !d.hidden
e.hidden = !e.hidden
f.hidden = !f.hidden
g.hidden = !g.hidden
a.hidden = !a.hidden
b.hidden = !b.hidden
cFour.hidden = !cFour.hidden
}
答案 1 :(得分:0)
正如@matt在评论中建议的那样,你可以使用:
@IBAction func settingsCheck(sender: UIButton) {
if c.hidden == false {
c.hidden = true
d.hidden = true
e.hidden = true
f.hidden = true
g.hidden = true
a.hidden = true
b.hidden = true
cFour.hidden = true}
else {
c.hidden = false
d.hidden = false
e.hidden = false
f.hidden = false
g.hidden = false
a.hidden = false
b.hidden = false
cFour.hidden = false
}
}