I am following a tutorial that is using ARSCNView
with ARImageTrackingConfiguration
to create an interactive AR Image Anchor. When you scan a specific image, a swift UI view is overlayed on top of it, and when the button is tapped in that Swift UI view, the overlay changes (with button animation and everything). I could replicate this exact behaviour, but the project was using UIKit with Storyboard as the basis. I wanted to replace that to use SwiftUI, and just call the ARSCNView through a UIViewControllerRepresentable. Problem is: this small change breaks the interactive part of the scanning. So the Swift UI view appears on top of the image, but the button is not working anymore.
The working version with UIKit and Storyboard is here: https://github.com/riccqi/ARImageTracking/tree/main
My version is here: https://github.com/harcipulyka/ARSCNViewIssue/tree/main
In both repos, only the signing has to be set, images are in the asset folder.
(I don't know which part breaks the functionality, and I hope it's not a bug on Apple's side, but below is the part I suspect could cause the difference)
In the AnchorView
file I have the UIViewControllerRepresentable
, where the update function is empty and the make function is as follows:
func makeUIViewController(context: Context) -> AnchorViewController {
let vc = AnchorViewController()
vc.sceneView = ARSCNView()
return vc
}
And in the AnchorViewController
file, the changes are the following:
- The
ARSCNView
property named sceneView is not an IBOutlet anymore - in the viewDidLoad function, I added two lines
view.addSubview(sceneView)
setConstraints()
where the setConstraints function is just setting the constraints to the parent view's constraints.