How do I disable the automatic activation of an ARCoachingOverlayView?

Viewed 722

I am adding an ARCoachingOverlayView to my ARView like this

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

Later, If I do

coachingOverlay.activatesAutomatically = false

has no effect. coachingOverlay continues to work normally.

How do I disable it immediately when I want?

1 Answers

An instance method setActive(_:animated:) controls whether coaching is in progress or not.

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

Here's what Apple documentation says:

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)

Or as alternative you can use isHidden property:

// ABRUPTLY
ARCoachingOverlayView().isHidden = true
Related