ios - 游戏场景到 View Controller

标签 ios swift

如何使用Swift 3将游戏场景链接到视图控制器?

我只是创建了一个按钮,但是在函数touchesEnded上创建的链接不起作用。

    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch = touches.first
    let touchLocation = touch!.location(in: self)

    if buttonHome.contains(touchLocation) {
        print("tapped!")
        let home:UIViewController = FirstViewController()
        self.view?.window?.rootViewController!.present(home, animated: true, completion: nil)
    }
}

最佳答案

我假设您在游戏场景类中使用Xcode ..您应该将视图控制器设置为变量以分配..这是伪代码

Class your-game-scene {
    Var viewcontroller :: gameviewcontroller


}

您可能需要实例化新的声明,因此找到游戏控制器的配置文件并将其设置为您在课程中设置的视图控制器

关于ios - 游戏场景到 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41417651/

相关文章:

iphone - iPhone 上的 OpenGL ES 2.0 - 我可以使用多少个纹理单元?

iphone - TabBarImage大小不正确

ios - 具有自定义层的 UIButton 子类不会完全填充相邻 View 的空间

swift - 按 double 对 UITableView 进行排序

swift - Scene Kit Swift 节点多次旋转

javascript - react native : How to keep multi-line textinput visible above keyboard

iOS 从应用程序内给定的 url 查看 PDF

swift - 如何使用SwiftUI和Combine将子View的状态变化传播到父View?

swift - NSTextView.typingAttributes 接受的键是什么?

ios - 如何从 Alamofire 返回值