ARView停止在第二个viewDidLoad上工作

时间:2019-08-05 05:56:34

标签: ios swift augmented-reality realitykit

我有一个ARView被添加为UIViewController的子视图。在第一个viewDidLoad上,ARView被添加为子视图,并且显示得很好。但是,在向后导航并再次触发viewDidLoad之后,ARView不会出现。我已经确认它是作为子视图添加的,只是不可见。这是UIViewController的内容:

private var arView: ARView?

    override func viewDidLoad() {
        super.viewDidLoad()
        print("View did load")
        view.backgroundColor = UIColor.red
        arView = ARView(frame: UIScreen.main.bounds)
        view.addSubview(arView!)
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        print("View will appear")
        addTarget(target:"test",arView:arView!)
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        print("View did appear")
        UIApplication.shared.isIdleTimerDisabled = true
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        print("View will disappear")
        view.subviews.forEach({ $0.removeFromSuperview() })
        UIApplication.shared.isIdleTimerDisabled = false
    }

0 个答案:

没有答案