我正在尝试开发一款文字游戏,让玩家点击按钮选择字母。
似乎有问题,我的按钮有时不会记录触摸。只有在触摸按钮之前没有用户交互的几秒钟暂停时才会出现这种情况。如果第一次触摸有效,快速跟进也会起作用。
@IBAction func tileButton1(_ sender: UIButton) {
print("Tile 1 Selected")
tileSelected(tileSelected: 1)
}
@IBAction func clearButton(_ sender: Any) {
clearSelectedTiles()
}
@IBAction func SubmitButton(_ sender: Any) {
//print("Submit Button Pressed")
checkIfSubmittedWordIsValid()
}
checkIfSubmittedWordIsValid
func checkIfSubmittedWordIsValid() {
var alreadySelectedWords: [String] = []
switch currentPlayer {
case 1:
alreadySelectedWords = player1words
case 2:
alreadySelectedWords = player2words
case 3:
alreadySelectedWords = player3words
case 4:
alreadySelectedWords = player4words
default:
break
}
if currentWord.characters.count < 3 {
print("Too short")
playSound(fileName: "invalidWord", fileExtension: "aiff", volume: 1.0)
} else if alreadySelectedWords.contains(currentWord) {
print("Already picked this word")
playSound(fileName: "invalidWord", fileExtension: "aiff", volume: 1.0)
} else if wordList.contains(currentWord.lowercased()) {
print("Valid Word")
playSound(fileName: "goodWord", fileExtension: "wav", volume: 0.5)
addWordToPlayerList(word: currentWord)
} else {
print("Not in dictionary")
playSound(fileName: "invalidWord", fileExtension: "aiff", volume: 1.0)
}
clearSelectedTiles()
}
clearSelectedTiles
func clearSelectedTiles() {
tile1.alpha = 1
tile2.alpha = 1
tile3.alpha = 1
tile4.alpha = 1
tile5.alpha = 1
tile6.alpha = 1
tile7.alpha = 1
tile8.alpha = 1
tile9.alpha = 1
tile10.alpha = 1
tile11.alpha = 1
tile12.alpha = 1
tile13.alpha = 1
tile14.alpha = 1
tile15.alpha = 1
tile16.alpha = 1
selectedTiles.removeAll()
validTiles = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
selectedWordLabel.text = ""
currentWord = ""
}
发生问题时不会打印任何内容。通过第二次触摸快速跟进将触发IBAction并打印以记录。
似乎还发生了我所有的其他按钮(另外15个'瓷砖'按钮和'清除'和'提交'按钮)
我做错了什么?
Link to video showing issue前几次接触工作但很奇怪。
tileSelected
func tileSelected(tileSelected: Int) {
if isTileValid(tile: tileSelected) {
selectedTiles.append(tileSelected)
var surroundingTiles: [Int] = []
switch tileSelected {
case 1:
tile1.alpha = 0.5
surroundingTiles = [2,5,6]
case 2:
tile2.alpha = 0.5
surroundingTiles = [1,3,5,6,7]
case 3:
tile3.alpha = 0.5
surroundingTiles = [2,4,6,7,8]
case 4:
tile4.alpha = 0.5
surroundingTiles = [3,7,8]
case 5:
tile5.alpha = 0.5
surroundingTiles = [1,2,6,9,10]
case 6:
tile6.alpha = 0.5
surroundingTiles = [1,2,3,5,7,9,10,11]
case 7:
tile7.alpha = 0.5
surroundingTiles = [2,3,4,6,8,10,11,12]
case 8:
tile8.alpha = 0.5
surroundingTiles = [3,4,7,11,12]
case 9:
tile9.alpha = 0.5
surroundingTiles = [5,6,10,13,14]
case 10:
tile10.alpha = 0.5
surroundingTiles = [5,6,7,9,11,13,14,15]
case 11:
tile11.alpha = 0.5
surroundingTiles = [6,7,8,10,12,14,15,16]
case 12:
tile12.alpha = 0.5
surroundingTiles = [7,8,11,15,16]
case 13:
tile13.alpha = 0.5
surroundingTiles = [9,10,14]
case 14:
tile14.alpha = 0.5
surroundingTiles = [9,10,11,13,15]
case 15:
tile15.alpha = 0.5
surroundingTiles = [10,11,12,14,16]
case 16:
tile16.alpha = 0.5
surroundingTiles = [11,12,15]
default:
// do nothing
break
}
updateValidTiles(surroundingTiles: surroundingTiles)
//print("Updated Valid Tiles")
//print(validTiles)
//print("Selected Tiles")
//print(selectedTiles)
currentWord = currentWord + boardTiles[tileSelected - 1].tileLetter
selectedWordLabel.text = currentWord
}
}
答案 0 :(得分:0)
尝试更改触摸按钮以在内部触摸,并尝试在每次单击时更改按钮的状态
答案 1 :(得分:0)
即使我使用class First
{
public static void main(String[] args)
{
double b = 012e3;
System.out.println(b);
}
}
隐藏了状态栏,我也有一些约束到Top Layout Guide.bottom
的标签。
将相关标签限制更改为override var prefersStatusBarHidden
而不是topMargin
已解决了我的问题,有时会错过触摸。