英文:
how to fix Cannot convert return expression of type 'UIView' to return type 'ARView' issue in swift?
问题
class MyCustomUIViewController: UIViewController {
let coachingOverly = ARCoachingOverlayView()
override func viewDidLoad() {
let arView = ARView(frame: .zero)
let session = arView.session
coachingOverly.autoresizingMask = [.flexibleWidth, .flexibleHeight]
coachingOverly.goal = .anyPlane
coachingOverly.session = session
arView.addSubview(coachingOverly)
let anchor = try! Dumu.loadScene()
arView.scene.anchors.append(anchor)
self.view.addSubview(arView)
}
override func viewWillAppear(_ animated: Bool) {
coachingOverly.setActive(true, animated: true)
}
}
英文:
class MyCustomUIViewController: UIViewController {
let coachingOverly = ARCoachingOverlayView()
override func viewDidLoad() {
let arView = ARView(frame: .zero)
let session = arView.session
// this is a view that display standardized onbording instructions to direct users towards specific goal.
let coachingOverly = ARCoachingOverlayView()
// this is an intger bit mask that determines how the reciever resized itself.
coachingOverly.autoresizingMask = [.flexibleWidth,.flexibleHeight]
coachingOverly.goal = .anyPlane
coachingOverly.session = session
arView.addSubview(coachingOverly)
// Load the "Opject" scene from the "dumu" Reality File
let anchor = try! Dumu.loadScene()
// Add the Opject anchor to the scene
arView.scene.anchors.append(anchor)
self.view.addSubview(arView)
}
override func viewWillAppear(_ animated: Bool) {
coachingOverly.setActive(true, animated: true)
}
}
答案1
得分: 1
从您在ARViewContainer中的图片中我看到....
在
func makeUIView(context: Context) -> ARView // ..... -> you specify a return type of ARView
但接下来你实例化了一个新的UIView作为返回值
... = MyCustomViewController() // Seems to be an UIView->
它似乎是一个UIView,但你必须返回一个ARView,它是UIView的子类。也许你可以使用下面的代码将MyCustomViewController进行类型转换:
let viewController = MyCustomUIViewController() as ARView
或者你可以在MyCustomUIViewController()的定义中将其类更改为ARView。要提供更详细的解释,我需要至少知道MyCustomUIViewController()的定义。
英文:
From your picture in the ARViewContainer I see....
In
func makeUIView(context: Context) -> ARView // ..... -> you specify a return type of ARView
But next you instantiate a new UIView for the return
... = MyCustomViewController() // Seems to be an UIView->
which seems to be an UIView and you return it. But you have to return an ARView which is a subclass of UIView. Maybe you can downcast the MyCustomViewController with
let viewController = MyCustomUIViewController() as ARView
or you may change the class of MyCustomUIViewController() to ARView in its definition. For a more detailed explanation I need at least the definition of MyCustomUIViewController()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论