Search code examples
swiftxcodeaugmented-realityarkitrealitykit

ARKit: How to add button to ARView in storyboard?


I am brand new to ARKit (and a novice in swift) but I am trying to create a basic AR app. I am following this tutorial in which a simple scene is created essentially doing everything in reality composer apart from the addition of a simple start scene button which is added to the ARView in the storyboard - you can see that specific moment in the tutorial here. When I attempt to do the same however, the button element replaces the ARView entirely, rather than it being added as a child of the ARView as happens in this tutorial.

You can see below a grab of what is going on. Here is the storyboard before I add the button.

Storyboard before adding button

I then search for a button element, drag onto ARView, at which point it replaces it, rather than adding as child. See below the result.

Storyboard after adding button

My xcode version is 11.2.

Any advice is much appreciated, and if any more info is needed, please ask. Thank you.


Solution

  • You must nest both the ARView and Button under a UIView. First, add a UIView as a direct child to the ViewController. Then, add an ARView under the UIView that you created before. Then, you can also add a UIButton under that same UIView.

    Edit: After Viewing the tutorial video linked in your question, the "ARView" the tutorial has as the child of the ViewController is not an actual ARView but a UIView renamed to "ARView", to clarify.