Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 触摸功能开始检测swift中游戏视图控制器外部的触摸_Ios_Swift - Fatal编程技术网

Ios 触摸功能开始检测swift中游戏视图控制器外部的触摸

Ios 触摸功能开始检测swift中游戏视图控制器外部的触摸,ios,swift,Ios,Swift,我已使用以下功能检测iOS应用程序中的触摸:- @IBOutlet var currentView: UIView! override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { super.touchesBegan(touches, with: event) if gameState == .ready { startGame() }

我已使用以下功能检测iOS应用程序中的触摸:-

@IBOutlet var currentView: UIView!

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesBegan(touches, with: event)

    if gameState == .ready {
      startGame()
    }
    
    let touch = touches.first
    guard let location = touch?.location(in: self.view) else { return }
    if currentView.frame.contains(location) {
        // Move the player to the new position
        movePlayer(to: location)
        
        // Move all enemies to the new position to trace the player
        moveEnemies(to: location)
    } else {
        print("Tapped outside the view")
    }
}
@IBOutlet var currentView:UIView!
覆盖func TouchesBegind(Touchs:Set,带有事件:UIEvent?){
super.touchesbeated(touches,with:event)
如果游戏状态==.ready{
startGame()
}
让我们先接触
guard let location=touch?.location(在:self.view中)else{return}
如果currentView.frame.contains(位置){
//将玩家移动到新位置
移动播放器(至:位置)
//将所有敌人移动到新位置以追踪玩家
移动敌人(至:位置)
}否则{
打印(“在视图外点击”)
}
}
但是,在对游戏结果V.C.执行一个序列后,它检测到游戏V.C.之外的触摸,因此应用程序崩溃!如果有人能告诉我如何解决这个问题,我将不胜感激?谢谢