我在这里有一个tic tac toe游戏,我需要一种方法来禁用已经播放过的空间上的轻击手势识别,以便在用户轮流时,用户不能只是点击已播放的地方。
我正在考虑某种类似于
的if-else语句if plays[imageViewTapped.tag] == true {
imageView.userInteractionEnabled = false
}
以上不起作用,所以我需要帮助。代码:
var plays = [Int:Int]()
var done = false
var aiDeciding = false
var ticTacImages = [UIImageView]()
for imageView in ticTacImages {
imageView.userInteractionEnabled = true
imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "imageClicked:"))
}
}
//Gesture Reocgnizer method
func imageClicked(reco: UITapGestureRecognizer) {
var imageViewTapped = reco.view as UIImageView
println(plays[imageViewTapped.tag])
println(aiDeciding)
println(done)
opening1.hidden = true
opening2.hidden = true
opening3.hidden = true
if plays[imageViewTapped.tag] == nil && !aiDeciding && !done {
setImageForSpot(imageViewTapped.tag, player:.UserPlayer)
}
checkForWin()
答案 0 :(得分:0)
当用户点击空白区域时,请执行常规操作并使用:
imageView.removeGestureRecognizer(myGestureRecognizer)
这应该可以防止与tic tac toe网格中的'used'空格进行任何交互。