In an Xcode MultiPlatorm App, the following works as expected (detecting tap gestures) in iOS simulator, but not when compiled and run on "My Mac" -- on Mac OS the view doesn't seem to get any clicks.
Does anyone know a way to get this to work?
One of the reasons
import SwiftUI
import SceneKit
class RenderDelegate: NSObject, SCNSceneRendererDelegate {
var lastRenderer: SCNSceneRenderer!
func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
lastRenderer = renderer
}
}
class Model: ObservableObject {
let scene = SCNScene()
let renderDelegate = RenderDelegate()
}
struct ContentView : View {
@ObservedObject var model = Model()
@State private var pointOfView = "distantCamera"
init() {
let sphereGeometry = SCNSphere(radius: 0.05)
#if os(iOS) || os(watchOS) || os(tvOS)
sphereGeometry.firstMaterial?.diffuse.contents = UIColor.red
#else
sphereGeometry.firstMaterial?.diffuse.contents = NSColor.red
#endif
let sphereNode = SCNNode(geometry: sphereGeometry)
sphereNode.position = SCNVector3Make(0.0, 0.0, 0.0)
model.scene.rootNode.addChildNode(sphereNode)
}
var body: some View {
ZStack {
SceneView(
scene: model.scene,
options: [ .allowsCameraControl ],
delegate: model.renderDelegate
).onTapGesture {print("tap")}
}
.padding()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}