【发布时间】:2017-09-02 15:05:09
【问题描述】:
我想在我的应用中引入一个开关,让用户可以启用或禁用功能点。
我说的功能是:
self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]
是否可以禁用它或仅以一种方式禁用它?
谢谢!
【问题讨论】:
标签: ios swift augmented-reality arkit
我想在我的应用中引入一个开关,让用户可以启用或禁用功能点。
我说的功能是:
self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]
是否可以禁用它或仅以一种方式禁用它?
谢谢!
【问题讨论】:
标签: ios swift augmented-reality arkit
如果特征点是您打开的唯一调试选项,您可以通过将调试选项设置为空集轻松将其关闭(以及所有其他调试选项):
self.sceneView.debugOptions = []
如果您设置了其他调试选项并希望删除仅特征点之一,则需要采用当前的debugOptions 值并应用一些SetAlgebra 方法来删除你不想要的选项。 (然后将debugOptions 设置为您修改后的集合。)
【讨论】:
答案是肯定的,
您可以启用 / 禁用
Feature Points,即使其他debugOptions是ON。您可以使用insert(_:)和remove(_:)实例方法来完成此操作。
这是一个代码(Xcode 10.2.1、Swift 5.0.1、ARKit 2.0):
let configuration = ARWorldTrackingConfiguration()
@IBOutlet weak var `switch`: UISwitch!
var debugOptions = SCNDebugOptions()
override func viewDidLoad() {
super.viewDidLoad()
sceneView.delegate = self
let scene = SCNScene(named: "art.scnassets/model.scn")!
debugOptions = [.showWorldOrigin]
sceneView.debugOptions = debugOptions
sceneView.scene = scene
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
sceneView.session.run(configuration)
}
@IBAction func featurePointsOnOff(_ sender: Any) {
if `switch`.isOn == true {
debugOptions.insert(.showFeaturePoints)
sceneView.debugOptions = debugOptions
print("'showFeaturePoints' option is \(debugOptions.contains(.showFeaturePoints))")
} else if `switch`.isOn == false {
debugOptions.remove(.showFeaturePoints)
sceneView.debugOptions = debugOptions
print("'showFeaturePoints' option is \(debugOptions.contains(.showFeaturePoints))")
}
}
希望这会有所帮助。
【讨论】: