how to fix Cannot convert return expression of type 'UIView' to return type 'ARView' issue in swift?

huangapple go评论55阅读模式
英文:

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)
    }
}
英文:

enter image description here

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()

huangapple
  • 本文由 发表于 2023年2月8日 19:59:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定