gpt4 book ai didi

swift - 未使用选择器操作调用函数

转载 作者:行者123 更新时间:2023-11-30 13:14:54 24 4
gpt4 key购买 nike

我试图在外部 UIViewController 的类中处理点击手势,但我的函数从未被调用。这是我的代码:

import SceneKit
import UIKit

class SceneManager
{
private let assetFolder: String
private let mainCamera: SCNNode
private let view: SCNView
private let scene: SCNScene

init(view: SCNView, assetFolder: String, sceneFile: String, mainCameraName: String, backgroundColor: UIColor) {
self.assetFolder = assetFolder
self.scene = SCNScene(named: (self.assetFolder + "/scene/" + sceneFile))!
self.mainCamera = self.scene.rootNode.childNodeWithName(mainCameraName, recursively: true)!
self.view = view
self.view.backgroundColor = backgroundColor
self.view.allowsCameraControl = false
self.view.pointOfView = self.mainCamera
self.view.scene = self.scene

//PROBLEM BELOW
let gesture = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
self.view.addGestureRecognizer(gesture)
}

@objc func handleTap(sender: UITapGestureRecognizer) {
print("hello")
}
}

这是我的 ViewController 类:导入 UIKit导入QuartzCore导入SceneKit

class ViewController: UIViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
let view = self.view as! SCNView
view.showsStatistics = true

_ = SceneManager(view: view, assetFolder: "art.scnassets", sceneFile: "EURO_COPTER.dae", mainCameraName: "camera", backgroundColor: UIColor.blackColor())
}
}

如果有人有想法。提前致谢。

最佳答案

尝试以下代码可能会有所帮助

let gesture = UITapGestureRecognizer(target: self, action: #selector(SceneManager.handleTap(_:)))

关于swift - 未使用选择器操作调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38329268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com