【发布时间】:2020-05-17 19:24:18
【问题描述】:
我在 Xcode 11.4 中预览时遇到了一些问题。我的手机插上电源时我的代码正在工作,所以这不是代码问题,但是拔掉电源时,构建总是失败。我希望能够在不使用 AR 的其他文件上处理我的项目,而不会出现此错误。当我恢复对其他文件的预览时,由于此错误而被阻止。 我已经在 info.plist 文件中添加了一些字符串(隐私摄像头使用和所需的设备功能),但仍然无法正常工作。有想法吗?
import SwiftUI
import RealityKit
struct ContentView : View {
var body: some View {
return ARViewContainer().edgesIgnoringSafeArea(.all)
}
}
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
arView.enablePlacement()
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
}
extension ARView {
func enablePlacement() {
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(handleTap(recognizer:)))
self.addGestureRecognizer(tapGestureRecognizer)
}
@objc func handleTap(recognizer: UITapGestureRecognizer) {
let location = recognizer.location(in: self)
let results = self.raycast(from: location, allowing: .estimatedPlane, alignment: .vertical)
if let firstResult = results.first {
let mesh = MeshResource.generateBox(width: 0.5, height: 0.02, depth: 0.2)
var material = SimpleMaterial()
material.baseColor = try! MaterialColorParameter.texture(TextureResource.load(named: "glacier"))
let modelEntity = ModelEntity(mesh: mesh,materials: [material])
let anchorEntity = AnchorEntity(world: firstResult.worldTransform)
anchorEntity.addChild(modelEntity)
self.backgroundColor = .orange
self.scene.addAnchor(anchorEntity)
}else{
print("No Surface detected - move around device")
}
}
}
#if DEBUG
struct ContentView_Previews : PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
错误类型“ARView”的值没有成员“raycast”。
无法根据成员“estimatedPlane”推断上下文基础。
无法根据成员“垂直”推断上下文基础。
【问题讨论】:
-
嗨,吉姆,欢迎来到 SO!您应该在帖子本身中输入错误而不是链接它,因为链接可能随时关闭,并且不允许未来与您有类似问题的人获得有关正在发生的事情的正确上下文。
标签: swift xcode swiftui arkit realitykit