如何禁用 ARCoachingOverlayView 的自动激活?

How do I disable the automatic activation of an ARCoachingOverlayView?

我正在向我的 ARView 添加一个 ARCoachingOverlayView,就像这样

let coachingOverlayTemp = ARCoachingOverlayView()
coachingOverlayTemp.delegate = self
coachingOverlayTemp.session = self.session
coachingOverlayTemp.goal = .horizontalPlane
coachingOverlayTemp.activatesAutomatically = true
coachingOverlayTemp.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(coachingOverlayTemp)

coachingOverlay = coachingOverlayTemp // I store it to a variable on the class

稍后,如果我这样做

coachingOverlay.activatesAutomatically = false

没有效果。 coachingOverlay 继续正常工作。

如何在需要时立即禁用它?

一个实例方法 setActive(_:animated:) 控制训练是否正在进行。

open func setActive(_ active: Bool, animated: Bool)

Apple documentation 是这样说的:

If the animated property of setActive(_:animated:) is true, isActive and isHidden are false while the coaching overlay is fading out. When the coaching overlay is deactivated without animation, or when the animation finishes, ARKit notifies you by calling coachingOverlayViewDidDeactivate(_:).

// SMOOTHLY
ARCoachingOverlayView().setActive(false, animated: false)

或者您可以使用 isHidden 属性:

// ABRUPTLY
ARCoachingOverlayView().isHidden = true