我有一个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
}