xcode 如何解决Swift中无法将“UIView”类型返回表达式转换为“ARView”类型的问题?

cgfeq70w  于 2023-02-09  发布在  Swift
关注(0)|答案(1)|浏览(133)

enter image description here
类我的自定义UI视图控制器:UI视图控制器{让指导覆盖= AR指导覆盖视图()

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

}

bf1o4zei

bf1o4zei1#

从ARViewContainer中的图片我看到....

func makeUIView(context: Context) -> ARView // ..... -> you specify a return type of ARView

但接下来要示例化一个新的UIView以返回

... = MyCustomViewController() // Seems to be an UIView->

它看起来是一个UIView,你返回它。但是你必须返回一个ARView,它是UIView的子类。也许你可以用

let viewController = MyCustomUIViewController() as ARView

也可以在定义中将MyCustomUIViewController()的类改为ARView。要获得更详细的解释,我至少需要MyCustomUIViewController()的定义

相关问题